سؤال

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