src091
src091

Reputation: 2847

Find out where back button press is going

When user presses a back hardware button in my activity he will either be taken to a previous activity or to the home screen (depends on how he got into that activity in a first place). Is there a way to determine where exactly user will be taken inside of onBackPressed method?

Upvotes: 0

Views: 44

Answers (1)

Tristan
Tristan

Reputation: 3578

In your home and previous activity when you start the intent to go to this activity, you can add an extra to the Intent.

Intent.setExtra("PREVIOUS_ACTIVITY ", "HOME")

Then you can check in your activity onBackPressed() if it came from the home or another activity.

Upvotes: 2

Related Questions