Skip to content Skip to sidebar Skip to footer

Reauthenticate On Restart - Android

I need reauthenticate user credentials every time onRestart is called (usually this means the user has locked&unlocked the screen or put it on background and then returned to i

Solution 1:

Well, I used this to solve it:

privatestaticfinalintREAUTHENTICATE=80;

    privateboolean authenticated;

    @OverridepublicvoidonRestart() {
        if(authenticated)
            return;

        Intentintent=newIntent(this, LoginActivity.class);
        intent.setAction(LoginActivity.REAUTHENTICATE);
        startActivityForResult(intent, REAUTHENTICATE);
    }

    @OverridepublicvoidonStop() {
        authenticated = false;
    }

    @OverridepublicvoidonActivityResult(int requestCode, int resultCode, Intent data) {
        if(requestCode == REAUTHENTICATE)
            authenticated = true;
    }

Well, this it no what I expected but works, I hope someone find a better solution. Cause onRestart keep getting called after onActivityResult.

Solution 2:

Until got a good solution/suggestion from any one can try this .

1- Put a boolean variable inshared pref named AuthentacationNeeded
2- get that in OnRestart withdefault value true3-if value istruethen only startActivity
4- put that variable truein onpuase 

in Login activity 
4-   put that variable false Before finish()

Post a Comment for "Reauthenticate On Restart - Android"