TaskStackBuilder and extras for the back stack
2014-08-04 15:18
302 查看
notifications to create a back stack for the back button to go through. Normal flow of my app:
Activity A is launched from the launcher.
User selects an item from A, which launches B with extras for what to load.
User selects an item from B, this launches C with extras for what to load.
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.
My current TaskStackBuilder code:
TaskStackBuilder sBuilder = TaskStackBuilder.create( this ); sBuilder.addParentStack( ActivityC.class ); sBuilder.addNextIntent( launchIntent ); pIntent = sBuilder.getPendingIntent( 0, PendingIntent.FLAG_ONE_SHOT );
Clicking on the notification launches Activity C just fine, but when I press back it explodes with an
IllegalArgumentExceptionfrom
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?
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
This line:
sBuilder.addParentStack( ActivityC.class );
adds all parents declared for
ActivityCin
AndroidManifest.xmlin
<meta-data>.
I don't know what it is, I haven't used it. I doubt you need it.
This line adds intent to an array:
sBuilder.addNextIntent(launchIntent);
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);
and add them to builder:
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.
相关文章推荐
- Smashing The Stack For Fun And Profit
- The syntax for stack versus heap allocation of C++, C++/CLI and CSharp
- Fixing the Back Button and Enabling Bookmarking for AJAX Apps
- 栈溢出 详解 Smashing The Stack For Fun And Profit
- smashing the stack for fun and profit(译文)
- 溢出的经典文章:Smashing The Stack For Fun And Profit[译文]
- 溢出的经典文章:Smashing The Stack For Fun And Profit [En]
- 堆栈溢出:Smashing The Stack For Fun And Profit
- 堆栈溢出:smashing the stack for fun and profit[译文]
- Smashing The Stack For Fun And Profit
- The eventual following stack trace is caused by an error thrown for debugging purposes as well as to attempt to terminate the thread which caused the illegal access, and has no functional impact.
- 笔记学习Smashing The Stack for Fun and Profit example 3--怎样修改返回地址。
- 《Smashing The Stack For Fun And Profit》解读
- The eventual following stack trace is caused by an error thrown for debugging purposes as well as to attempt to terminate the thread which caused the illegal access, and has no functional impact
- 为了娱乐和利益粉碎栈(Smashing The Stack For Fun And Profit)
- How to Monitor Your Network Usage in Windows 8 (And Prevent Paying For The Extra Bandwidth)
- Smashing the Stack for Fun and Profit by Aleph One
- [转载]Smashing The Stack For Fun And Profit
- [译文]Smashing The Stack For Fun And Profit
- The Difference between write through and write back for cache