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..
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.
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.
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);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With