我想使用 TaskStackBuilder ,并通知制造的背堆栈背按钮来通过。我的应用程序的正常流动:
I'm trying to use TaskStackBuilder with notifications to create a back stack for the back button to go through. Normal flow of my app:
在活动A被从发射装置发射。 在用户从一个项目,这将启动B带额外的东西来加载。 在用户选择从B上的项目,这将启动下与额外的东西来加载。有时候,当用户没有使用我的应用背景更新后,我生成通知。如果他们点击此通知,它启动活动C,跳过A和B.我想遵循的设计指南,并创建一个回栈,所以当他们preSS回到它会在主屏幕到活动B代替。我的问题是,活动B需要在其推出的意图额外的告诉它怎么从数据库中抓取。
Sometimes, after a background update when the user isn't using my app, I generate a notification. If they click this notification, it launches Activity C, skipping A and B. I'm trying to follow the design guidelines and create a back stack, so when they press back it will go to Activity B instead of the home screen. My problem is that Activity B requires an extra in its launch intent to tell it what to grab from the database.
我目前TaskStackBuilder code:
My current TaskStackBuilder code:
TaskStackBuilder sBuilder = TaskStackBuilder.create( this );
sBuilder.addParentStack( ActivityC.class );
sBuilder.addNextIntent( launchIntent );
pIntent = sBuilder.getPendingIntent( 0, PendingIntent.FLAG_ONE_SHOT );
点击该通知将启动活动Ç就好了,但是当我preSS回它与抛出:IllegalArgumentException
从我的ContentProvider,因为活动B不知道爆炸是什么ID请求。有没有什么办法让这个额外的入后堆栈还是我停留?
Clicking on the notification launches Activity C just fine, but when I press back it explodes with an IllegalArgumentException
from my ContentProvider because Activity B doesn't know what ID to request. Is there any way to get this extra into the back stack or am I stuck?
这行:
sBuilder.addParentStack( ActivityC.class );
增加了 ActivityC
宣布所有的父母在的AndroidManifest.xml
在<荟萃数据>
。我不知道它是什么,我没有用它。我怀疑你需要它。
adds all parents declared for ActivityC
in AndroidManifest.xml
in <meta-data>
. I don't know what it is, I haven't used it. I doubt you need it.
这行添加意图数组:
sBuilder.addNextIntent(launchIntent);
则意图的阵列用于创建PendingIntent,可能与PendingIntent.getActivities,我找不到执行,然后在某处开始Context.startActivities.
then the array of intents is used to create PendingIntent, probably with PendingIntent.getActivities, I couldn't find the implementation, which is then started somewhere with Context.startActivities.
我觉得你只需要创建设置意图,有你可以添加额外的:
I think you just need to create set of intents, there you can add extras:
Intent activityA = new Intent(context, ActivityA.class);
activityA.putExtra(key, valueA);
Intent activityB = new Intent(context, ActivityB.class);
activityB.putExtra(key, valueB);
Intent activityC = new Intent(context, ActivityC.class);
activityC.putExtra(key, valueC);
和它们添加到生成器:
sBuilder.addNextIntent(activityA);
sBuilder.addNextIntent(activityB);
sBuilder.addNextIntent(activityC);
pIntent = sBuilder.getPendingIntent( 0, PendingIntent.FLAG_ONE_SHOT );
我没有测试过,这是我快速的研究只是一个结果,我希望有人会纠正我,如果我错了。
I haven't tested it, this is only a result of my fast research, I hope someone will correct me if I'm wrong.