I want to find out which activity started my activity in android. I can get the intent that started the activity using getIntent()
but I am not able to find out which activity started the intent in the first place.
Use startActivityForResult in your calling activity to start the activity: ActivityCompat. startActivityForResult(this, new Intent(this, MyActivity. class), 0, null);
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.
Activities will very often need to support the CATEGORY_DEFAULT so that they can be found by Context. startActivity(). So, CATEGORY_DEFAULT can appear number of times. Android does not grab whichever one appears first in the manifest but it starts with activity having CATEGORY_LAUNCHER.
An activity provides the window in which the app draws its UI. This window typically fills the screen, but may be smaller than the screen and float on top of other windows. Generally, one activity implements one screen in an app.
Use getCallingActivity()
Note: if the calling activity is not expecting a result (that is it did not use the startActivityForResult(Intent, int)
form that includes a request code), then the calling package will be null
You can use ActivityCompat.getReferrer()
for this purpose.
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