0

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?

src091
  • 2,807
  • 7
  • 44
  • 74

1 Answers1

2

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.

Tristan
  • 3,530
  • 3
  • 30
  • 39