0

This is my use case. I have to deep link into an activity that has a fragment associated with it. This deep link requires that we sign in to the app. This is my deep link flow

Deep Link Handler Activity -> (Sign In) -> (Preference Activity).

If you were to navigate to the destination activity after logging in, which loads the main screen, then the navigation path would be

(Main Activity) - > Activity A -> (Preference Activity)

The SignIn Activity calls the destination activity, and calls finish() thereby removing itself from the back stack. This is a legacy code, and can not be changed.

What I want to do is the following

After the destination activity is loaded after deeplink -> sign in, and if the user were to press the back button the first time, then I would like to load Activity A followed by Home Screen on another back button press.

Is there a way to achieve this? I have gone through the following tutorials

  1. Go back to different Activity in back stack in Android

  2. android activity back stack (This is the default behaviour).

My intent launch activity in the deep link handler activity.

Intent processorIntent = new Intent(this, PreferencesActivity.class);
processorIntent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
processorIntent.putExtra(PARAM_PREFERENCE, preference);
processorIntent.putExtra(PARAM_FLOW, true);
startActivity(processorIntent);
Kartik
  • 2,541
  • 2
  • 37
  • 59

1 Answers1

0
(Main Activity) - > Activity A -> (Destination Activity)

You need to call startActivity when user press back button first time from the Destination Activity like this

@Override
public void onBackPressed() {
    if(isFirstTime){
        Intent intent=new Intent(this, A.class);
        intent.putExtra(PARAM_FLOW, true);
        startActivity(intent);
        finish();
    }else super.onBackPressed();
}

and do the same thing in Activity A

Jignesh Mayani
  • 6,937
  • 1
  • 20
  • 36