Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android get previous activity

I have 2 activities: Activity1 and Activity2. In each of this activities there is a button that leads me to a third activity (MainActivity). In MainActivity I want to know from which activity page was called.

like image 235
tinti Avatar asked Nov 14 '11 09:11

tinti


2 Answers

You can use the putExtra attribute of the Intent to pass the name of the Activity.

Calling Activity,

Intent intent = new Intent(this, Next.class); intent.putExtra("activity","first"); startActivity(intent); 

Next Activity,

Intent intent = getIntent(); String activity = intent.getStringExtra("activity"); 

Now in the string activity you will get the name from which Activity it has came.

like image 64
Lalit Poptani Avatar answered Sep 21 '22 09:09

Lalit Poptani


You can use:

public ComponentName getCallingActivity() 

to know which Activity called your current Activity.

like image 27
brianestey Avatar answered Sep 20 '22 09:09

brianestey