I have an issue with one of my applications that is using a PendingIntent 
to launch an activity from a widget...

This is the piece of code that does the trick:
PendingIntent pendingIntent = PendingIntent.getActivity(ctx, widgetId, 
intent, PendingIntent.FLAG_UPDATE_CURRENT);
views.setOnClickPendingIntent(resId, pendingIntent);

Now let me explain you the cases:

This is the flow it should do:
[Widget]
-> Click button, launch activity
[StartTimeRegistrationActivity]
-> task needs to be selected so start TaskSelectionActivity for result 
automatically
[TaskSelectionActivity]
<- Task selected, so the TaskSelectionActivity is finished and coming back 
in the onActivityResult
-> Do some automated stuff in this activity
<- Finish the activity (so finish() and go into onDestroy())
If, from somewhere in my application, I start the activity manually (so 
without a pending intent) it's started correctly and executes correctly.

However if I start it with the PendingIntent with the flag set to 
PendingIntent.FLAG_UPDATE_CURRENT part of my flow is not executed anymore, 
specifically the onActivityResult of the StartTimeRegistrationActivity. So 
this becomes the flow:
[Widget]
-> Click button, launch activity
[StartTimeRegistrationActivity]
-> task needs to be selected so start TaskSelectionActivity for result 
automatically
[TaskSelectionActivity]
<- Task selected, so the TaskSelectionActivity is finished, but not coming 
in the onActivityResult but directly to the onDestory() method (not passing 
the finish() method anywhere)
If I change the pending intent to use the flag PendingIntent.FLAG_ONE_SHOT 
the flow is executed correctly. But then, when the 
StartTimeRegistrationActivity is open, and the user presses the back-button 
to cancel his action (a case that is perfectly acceptable for this 
application) he cannot click the button anymore because the 
PendingIntent.FLAG_ONE_SHOT declares that it will be automatically 
cancelled as soon as the send() method is called once on it.

So any ideas here how to work around it?

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to