NavUtils.navigateUpTo() does not start any Activity

前端 未结 9 2322
陌清茗
陌清茗 2021-01-30 06:48

I have two activities

  • MainActivity
  • DeepLinkActivity

I set up everything to use the NavUtils for navi

9条回答
  •  一个人的身影
    2021-01-30 07:33

    I think that method is bugged. I've read support library source code, and that method check for intent's action. It only works when your App was previously created..as you've described, if you kill it from Apps preview, shouldUp method stops working.

    I've fixed this using my own "shouldUpRecreateTask". When I receive a Notification that creates directly an Activity (Like your behaviour), I send from my BroadCastReceiver a custom Action inside the intent. Then, in my Method I do the next thing:

    private final boolean shouldUpRecreateTask(Activity from){
        String action = from.getIntent().getAction();
        return action != null && action.equals(com.xxxxxx.activities.Intent.FROM_NOTIFICATION);
    }
    

    ..........................

     if (shouldUpRecreateTask(this)) {
          TaskStackBuilder.create(this)
           .addNextIntentWithParentStack(upIntent)
           .startActivities();
     } else {
           fillUpIntentWithExtras(upIntent);
           NavUtils.navigateUpTo(this, upIntent);
     }
    

提交回复
热议问题