Up to parent activity - on Android

后端 未结 7 1625
有刺的猬
有刺的猬 2021-01-17 13:06

After receiving a notification in my app, clicking on it opens activity B. Activity B has a parent activity A. Here is the manifest:



        
7条回答
  •  清歌不尽
    2021-01-17 13:34

    I use the following code and it works like a charm. Have a go!

    Intent upIntent = new Intent(getApplicationContext(), Home.class);
    if (NavUtils.shouldUpRecreateTask(this, upIntent)) {
        Log.d("ShowNotifications", "New Home");
        TaskStackBuilder.create(this).addNextIntentWithParentStack(upIntent).startActivities();
    } else {
        Log.d("ShowNotifications", "Old Home");
        upIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP|Intent.FLAG_ACTIVITY_SINGLE_TOP);
        //upIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK );
        startActivity(upIntent);
        finish();
    }
    

提交回复
热议问题