Pergunta

I have an application where it has a Login Screen as the Main Activity. Now I want the app to be launched from this screen on each time the app is run. But when I run the app from minimized state, it launches the app from the last activity. I know this is the default behavior.

But, how to over come this, so that the app gets launched from the Home activity only each time.

I tried setting noHistory for activity in manifest. But in this case, I will have to override onBackPressed in each activity and start the activity multiple times.

Can any one suggest me other methods to do this.

Foi útil?

Solução

Implement this 2 methods in your all your required activity.

boolean flag = true;
@Override
protected void onStart() {
    // TODO Auto-generated method stub
    super.onStart();
    if(flag)
    Toast.makeText(getApplicationContext(), "start", 1).show();
    else
    {
        Toast.makeText(getApplicationContext(), "Restart 2", 1).show();
        Intent i = new Intent(SecondActivity.this,MainActivity.class);
        finish();
        startActivity(i);

    }
}

@Override
protected void onRestart() {
    // TODO Auto-generated method stub
    super.onRestart();
    Toast.makeText(getApplicationContext(), "Restart", 1).show();
    flag = false;
}

so when you re open app from background than it will redirect to your LoginActivity.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top