Start multiple activities from Notification via PendingIntent

ⅰ亾dé卋堺 提交于 2019-12-13 11:09:38

问题


I'd like to start multiple activities when press on Notification. I didn't find any docs about how to set multiple intents in a single PendingIntent.

One solution could be to start next activity in the first one's onCreate() and so forth, but I don't like this, maybe there is something else.


回答1:


Finally, I got the answer for this - it's pretty trivial, just using method getActivities() to the PendingIntent like so:

        Intent myIntent1= new Intent(ctx, MyActivity1.class);
        myIntent1.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NO_ANIMATION);

        Intent myIntent2= new Intent(ctx, MyActivity2.class);

        Intent[] intents = new Intent[]{myIntent1, myIntent2};
        PendingIntent pendingIntent = PendingIntent.getActivities(ctx, pid, intents, PendingIntent.FLAG_ONE_SHOT);


来源:https://stackoverflow.com/questions/50942043/start-multiple-activities-from-notification-via-pendingintent

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!