Skip to content Skip to sidebar Skip to footer

How Can I Finish "group" Of Activities?

I have an operation in my Android app which includes a couple of activities. At the end of this operation, I need to close all of these activities and go back to the screen which s

Solution 1:

There are a lot of ways to do this. Shortly they are: 1. Start all your activity with startActivityOnResult() method. And catch if you need to close them 2. start Activity_1 with cleaning current backstack:

intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK); 
startActivity(intent);
finish(); 

3. Activities located inside of processes. You can define another process in the AndroidManifest for your activities(3,4,5). After that you need to return to previous process and remove current process from backStack.

Solution 2:

you can use flag=Intent.FLAG_ACTIVITY_CLEAR_TASK to finish group of activities. here is example of code

 startActivity(new Intent(SignIn.this, MainActivity.class).setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_CLEAR_TASK));

Solution 3:

you can use flag=Intent.FLAG_ACTIVITY_CLEAR_TASK to clear all previous activity . This flag is used to clear all previous activity .

try this code

//  go to login activity

Intent intent =newIntent(AddNewCardActivity.this,HomeNavigationActivity.class);
      intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
            startActivity(intent);
            finish();

Post a Comment for "How Can I Finish "group" Of Activities?"