when i click the back button on an android device, the onBackPressed will fire and it will navigate me to the previous activity.
is there a way how i can know which is the previous activity?
thanks in advance
clive
when i click the back button on an android device, the onBackPressed will fire and it will navigate me to the previous activity.
is there a way how i can know which is the previous activity?
thanks in advance
clive
Assuming you only want to know the name of the previous Activity
, you can put the name of the previous Activity
in the Intent using putExtra(String name, String value)
method. Then you can get the name of the Activity in onCreate
of the child Activity by using getStringExtra(String name)
method on the Activity's Intent. You can get the intent by using the getIntent()
method of the Activity.
You could use getCallingActivity
if you started the activity to get results.
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.
So maybe you can hack it by starting the activities for result without actually providing a result.