通过PendingIntent从Notification启动多个活动 [英] Start multiple activities from Notification via PendingIntent
本文介绍了通过PendingIntent从Notification启动多个活动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
按通知"时,我想开始多个活动.我没有找到任何有关如何在单个PendingIntent
中设置多个意图的文档.
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
.
一个解决方案可能是在第一个活动的onCreate()中启动下一个活动,依此类推,但是我不喜欢这样,也许还有其他事情.
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.
推荐答案
最后,我得到了答案-这很简单,只是对PendingIntent
使用方法getActivities()
就像这样:
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);
这篇关于通过PendingIntent从Notification启动多个活动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文