-2

There are multiple activities that can trigger registration activity in my app.

Registration activity consists of 5 activities activities. Now once registration is completed I want to take the user to ProfilePageActivity, and when the user presses back button from ProfilePageActivity, I want to take the user to the activity they were in when they called RegistrationActivity

If I use these;

intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);

they will remove the entire stack, and when the user presses the back button it will exit the application.

I want to know if there is any way I can define the range of activities to be deleted from the stack.

Abhishek Bhardwaj
  • 1,164
  • 3
  • 14
  • 39
dev90
  • 7,187
  • 15
  • 80
  • 153

2 Answers2

1

You can use TaskStackBuilder ,try this

TaskStackBuilder.create(this)
                            .addNextIntent(mainActivityIntent())
                            .addNextIntentWithParentStack(myTripActivityIntent())
                            .startActivities();

And function is

private Intent mainActivityIntent() {
        Intent intent = new Intent(this, MainActivity.class);
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        return intent;
    }

    private Intent myTripActivityIntent() {
        Intent intent = new Intent(this, MyTripActivity.class);
        return intent;
    }
Sandeep Parish
  • 1,888
  • 2
  • 9
  • 20
1

It is best to use Fragment in your RegisterActivity.

if you still want to do like this, you should use startActivityforResult. when last activity has finish button click, finish activity with RESULT_OK. now in 4th activity check result, if it RESULT_OK then do same process untill. it comes to first activity that is RegisterActivity. now here if you get RESULT_OK then call your ProfilePageActivity.

Shubham Vala
  • 1,024
  • 7
  • 18