Android - Clear task flag not working for PendingIntent

后端 未结 9 1965
夕颜
夕颜 2020-12-17 09:34

I have a task stack of A > B > C. I am currently on C, and then I press the home button. I get a notification with the intent to take me to Activity A. I press the notificat

9条回答
  •  星月不相逢
    2020-12-17 10:10

    I had loads of problems with this, and thought I was going crazy until I uninstalled/reinstalled my App and hey presto, the code works as per many posts on Stack Overflow. I was doing the following:

    Intent i = new Intent(getApplicationContext(), MainActivity.class);
    i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
    
    PendingIntent pi = PendingIntent.getActivity(this, 0, i, 0);
    

    and was continually getting two versions of the App. After an uninstall on one device, and re-starting the other device everything now behaves as expected with a single instance. Hope this helps you.

提交回复
热议问题