Android remove Activity from back stack

后端 未结 11 2039
予麋鹿
予麋鹿 2020-12-07 17:23

Okay so I\'m kind of stumped on what to do with this. So I have the MainActivity, and from there an Activity can be launched to DegreePlanActivity, and from there another Ac

相关标签:
11条回答
  • I would suggest that you use startActivityForResult(), instead of simply startActivity(), when you launch the EditDegreePlan-Activity, as described in the Android tutorials.

    In the EditDegreePlan-Activity you then call

    setResult(RESULT_OK);
    finish();
    

    If you don't expect any data from the EditDegreePlan-Activity, then you don't necessarily have to implement the onActivityResult.

    0 讨论(0)
  • 2020-12-07 18:01

    simple solution for API >= 15 to API 23 user activity name in intent.

     Intent nextScreen = new Intent(currentActivity.this, MainActivity.class);
     nextScreen.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | IntentCompat.FLAG_ACTIVITY_CLEAR_TASK);
     startActivity(nextScreen);
     ActivityCompat.finishAffinity(currentActivity.this);
    
    0 讨论(0)
  • 2020-12-07 18:04

    FLAG_ACTIVITY_CLEAR_TOP clears your Activity stack , you can use the code below:

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

    Remember that this flag clears just Intermediate Activities , for example if you have A,B,C in your Back Stack then going from C Activity to D with this flag this does not clear Back Stack and the Stack would be A,B,C,D but if you go from Activity D to Activity A with this flag , B,C,D Activities will pop up from the stack and you will have just A in the Back Stack .

    0 讨论(0)
  • 2020-12-07 18:04
    Intent intent = new Intent(getContext(), MainActivity.class);
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK); 
    
    startActivity(intent);
    
    0 讨论(0)
  • 2020-12-07 18:15

    You can add flags as follows and start Activity, try below code

    Intent i = new Intent(activity, Payment.class);
    i.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY | Intent.FLAG_ACTIVITY_CLEAR_TOP);
    activity.startActivity(i);
    
    0 讨论(0)
提交回复
热议问题