Android - Build a notification, TaskStackBuilder.addParentStack not working

前端 未结 11 2611
说谎
说谎 2020-11-28 06:23

I\'m trying to launch an activity from a notification like the Android docs explain, but when I open the notification and then press the back button, the HomeActivity (paren

11条回答
  •  野趣味
    野趣味 (楼主)
    2020-11-28 06:46

    As stated in other answers, TaskStackBuilder doesn't work for versions below Honeycomb.

    My solution was to override the activity's onBackPressed() method.

    @Override
    public void onBackPressed() {
        NavUtils.navigateUpFromSameTask(this);
    }
    

    Obviously if you're planning on finishing the activity in some other manner you will have to handle that as well. (Though I imagine overriding finish() will have some unexpected behaviour).

提交回复
热议问题