0

I need to show a login screen each time user is openning or switching between the apps. I have implemented a solution to open a LoginActivity in needed cases. When user open a minimised app, LoginActivity was opened on the top of the backstack. As I wanted to make app secure and restrict back navigation, I used Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK flags, so the backstack was cleared.

But now I need to keep a backstack. What would be a better solution? Save the state of the openned activities (and how to do it better)? Or to restrict back button navigation somehow and just finish LoginActivity if the login was successfull? Is it safe to show LoginActivity ot the top of the backstack?

Vadims Savjolovs
  • 2,618
  • 1
  • 26
  • 51

1 Answers1

1

In my opinion if the user presses the back button while is in the login screen the application has to be closed and the backstack cleaned. But, it is okay for me to bring the LoginActivity at the top of the backStack starting that with the Intent flag Intent.FLAG_ACTIVITY_REORDER_TO_FRONT. If the login is successful the LoginActivity can be finished, so the user can continue with the opened Activities. But if the user presses the button back, the LoginActivitycan be finished and the backstack cleared you can use this.

In order to save the state of the opened Activities, you should use the state method events: onSaveInstanceState()... and save in the state the members that you need to save.

Community
  • 1
  • 1
antonicg
  • 934
  • 10
  • 24