0

I have a large number of activities in my app that I transition between using intents.I would like the app to start every time as if it had been cleared from the background. I can't find anywhere how to do this. Thanks.

2 Answers2

0

i suppose you want to start the app with the actvivities stack cleared.

Intent intent_activity=new Intent(MainActivity.this, Activity2.class);
            intent_activity.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            intent_activity.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
            startActivity(intent_activity);

use flags to make you shure the stack is cleared and declare the states of the life cycle of the activities

  @Override
protected void onCreate() {
    super.onCreate();
}

 @Override
protected void onStart() {
    super.onStart();
}

@Override
protected void onStop() {
    super.onStop();
}

@Override
protected void onPause() {
    super.onPause();
}

@Override
protected void onResume() {
    super.onResume();
}

@Override
protected void onDestroy() {
    super.onDestroy();
}
UrielUVD
  • 482
  • 1
  • 9
  • 27
0

try this

Intent intent = new Intent(ProfileActivity.this,
LoginActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); 
startActivity(intent);