Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Find out which activity started my activity?

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.

like image 481
user590849 Avatar asked Mar 17 '11 08:03

user590849


People also ask

How do you check which intent started the activity?

Use startActivityForResult in your calling activity to start the activity: ActivityCompat. startActivityForResult(this, new Intent(this, MyActivity. class), 0, null);

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.

How does Android know which activity to run first?

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.

What is activity this in Android?

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.


2 Answers

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

like image 195
Reno Avatar answered Oct 02 '22 07:10

Reno


You can use ActivityCompat.getReferrer() for this purpose.

like image 30
David Wasser Avatar answered Oct 02 '22 06:10

David Wasser