Android Linking Activities

In this article I am going to show how to link android activities using intent.
Suppose there is two or more activities in your application and you want to go one activity to another activity and come back to previous activity. In this example I will show you how we can do this.

Download Source

Launching Activity

Linking Activities

Linking Activities

Assume you are in to Main Activity and now we want to link to another. Simply create a new Intent object and set it target activity constructor and call startActivity() method to launch target activity.

And add targeted activity into AndroidManifest.xml under Application Node.

Launching Previous Activity

Linking Activity Back

Linking Activity Back

There is two ways to come back on Main activity. One is you can use same method as we used above, that is defining by intent and Another way is calling by finish() method.
But what finish() method does exactly?
The answer is, Using Intent we launch an Activity and it stacks but calling finish() method remove the activity from stack and launch previous activity.

Launching Activity using CreateChooser Method

Linking activity chooser
To use createChooser() method you need to specify string name of activity name. See the following code snippet.

Download Source

1 reply

Trackbacks & Pingbacks

  1. […] you can see in the previous post how we can Link Activities. But one of the most important thing is when we launch one activity to another, at the same time we […]

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply

Your email address will not be published. Required fields are marked *