Understanding How Up-Navigation Transition Destinations Are Determined

Asked 2 years ago, Updated 2 years ago, 39 views

I can't get an answer to the following questions, so please let me ask you a question as well.

https://stackoverflow.com/questions/27767657/android-up-navigation-targetting

  • ActivityA(Aa):Activity
  • ActivityB(Ab):Activity with ViewPager
  • ActivityC(Ac):Activity(myapp://foo) with URI scheme
  • ActivityD(Ad):Activity
  • FragmentA(Fa):ViewPager item1
  • FragmentB(Fb):ViewPager item2
  • FragmentC(Fc):ViewPager item3
Aa→Ab(Fa)→Ac: Pattern 1
      ↓↑
     Ab(Fb) → Ad
      ↓↑
     Ab(Fc) → Ac: Pattern 1
Notification→ Ac: Pattern 2 
External Application → Ac: Pattern 2

For Pattern 1

Is there a general way to determine the transition destination?
The current implementation passes the values to determine the transition source as follows:
However, if the Up-Navigation target screen cannot be determined, it feels redundant to write this kind of code in all cases.

/*ActivityC.java*/
public static void launch (Context context, String from) {
    Intent = new Intent(context, ActivityC.class);
    // from —A unique value for each item in ViewPager
    int.putExtra(EXTRA_FROM, from);
    context.startActivity(intent);
}

For Pattern 2

How to determine the transition destination of Up-Navigation is as follows, but how
is originally used. Should it be implemented?
If there are many screens transitioning from ViewPager or URI Scheme, the following code will increase:

/*ActivityC.java*/
@Override public boolean onOptionsItemSelected(MenuItem){
  switch(item.getItemId()){
    case android.R.id.home:
      if(!getIntent().hasExtra(EXTRA_FROM)){
        // Consider transitioned via Notification or URI Scheme

        // I don't know if I'm going to transition to Ab(Fa) or Ab(Fc), so I'm going to fix it to Ab(Fa).
        Intent upIntent=ActivityB.createIntent(this,null);
        TaskStackBuilder.create(this)
          .addNextIntent(ActivityA.createIntent(this))
          .addNextIntent (upIntent)
          .startActivities();
        finish();
      } else{
        // consider transitioning from within this app
        String from = getIntent().getStringExtra(EXTRA_FROM);
        Intent upIntent=ActivityB.createIntent(this,from);
        NavUtils.navigateUpTo(this,upIntent);
      }
  }
  return true;
}

Background to Questions

At first, I thought it would be easy to write on AndroidManifest.xml, but in reality, I often encounter this kind of screen transition pattern, so I asked if there were any best practices.

android

2022-09-30 20:30

1 Answers

For each pattern, define another activity derived from Ac (Ac1, Ac2, Ac3 extensions Ac) and make it different on Manifest, and it will be refreshing on Manifest.


2022-09-30 20:30

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.