0

I created an app that has relatively many activities in it and I allow users to click on the return button which uses onBackPressed();

The users can click multiple times on this button in order to return some screen.

However, how can I know when it is the last activity before it exits the app?

Is there any way to know that at this specific click the app will close and not return to other activity?

Thank you

Ben
  • 1,737
  • 2
  • 30
  • 61
  • 1
    it's hard to help without some details. Can you try to clarify what is the flow, what does it mean exit app? Is it because the user clicked return from some specific screen? – limido Aug 10 '20 at 20:00
  • From any activity, if the user clicks enough times it will eventually exit the app and it came back to the first activity where it started from. – Ben Aug 10 '20 at 20:08
  • What is the logic of `onBackPressed()`? If you have a `Stack` then you can check that the size is one. – limido Aug 10 '20 at 20:14
  • use this question to find the last activity in back stack then implement onBackPressed for your desired purpose https://stackoverflow.com/q/5975811/8136868 – Reza Aug 10 '20 at 20:26

1 Answers1

0

Use isTaskRoot() to check if the activity is the root/first activity in a task. (Reference)

Chrisvin Jem
  • 3,940
  • 1
  • 8
  • 24