Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to find last activity from which current activity is opened in android?

I have one activity which can be open from more 4 or 5 different activity so i can find from which activity my current activity is called...

If any idea please help me..

like image 668
Dharmendra Avatar asked Mar 29 '11 04:03

Dharmendra


People also ask

How can I see my previous activity?

Android activities are stored in the activity stack. Going back to a previous activity could mean two things. You opened the new activity from another activity with startActivityForResult. In that case you can just call the finishActivity() function from your code and it'll take you back to the previous activity.

How do I find my current activity name?

Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project. Step 2 − Add the following code to res/layout/activity_main. xml. In the above code, we have taken text view to show activity name.


1 Answers

You might want to add extras to the intent you use to start the activity to indicate where the intent is coming from or what the request is.

For example:

Intent intent = new Intent(this, OtherActivity.class); intent.putExtra("caller", "MainActivity"); startActivity(intent); 

and then your OtherActivity could detect the "caller" in its onCreate:

String caller     = getIntent().getStringExtra("caller"); Class callerClass = Class.forName(caller); 
like image 108
Matthew Willis Avatar answered Oct 04 '22 00:10

Matthew Willis