Search code examples
androidoverridingonresumeactivity-lifecycle

Android - Clear existing objects and variables in memory when returning to Log In screen


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.


Solution

  • 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();