I have an issue where if my user is on the Dashboard screen and presses the phones 'Back' button, this will then return them to the login screen (which still has their details input) and if they login again, some variables are global so these are then effectively reused which effects the functionality of the application.

My thinking was I could override the onResume method when this activity is resumed and then clear everything but I am unsure on how to code this and clear the form and any variables still existing in the applications memory.

Thanks.

有帮助吗?

解决方案

finish() your login screen when you logged in.

For example:

//I'm logged in, starting dashboard view
startActivity(intent);
//finishing login activity - I don't need it on back stack
finish();

其他提示

The safest option would be to call finish() in the login activity after switching to the new activity. This will prevent the activity to go back to the login screen after pressing the back button, as that will remove that activity until it is manually started again.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top