synic synic - 4 days ago 5
Android Question

Selecting a specific Tab in a TabActivity from a PendingIntent sent from a Notification

I've got a TabActivity with 4 tabs in it. I have a service that is running - this service runs even after my TabActivity has been destroyed.

When the Service receives an event, I create a notification. The TabActivity may, at this time, be destroyed, or just running in the background.

How can I create a Notification/PendingIntent that will bring either launch the TabActivity if it is not currently running, or bring it to the front if it already is, and focus a specific tab based on the event?

I've thought about registering a broadcast receiver programmatically from within the TabActivity, and with this I'll be able to focus the tab, but how would I make the TabActivity the active Activity?

Answer

I think I found the answer.

http://developer.android.com/reference/android/app/Activity.html#onNewIntent(android.content.Intent)

This is called for activities that set launchMode to "singleTop" in their package, or if a client used the FLAG_ACTIVITY_SINGLE_TOP flag when calling startActivity(Intent). In either case, when the activity is re-launched while at the top of the activity stack instead of a new instance of the activity being started, onNewIntent() will be called on the existing instance with the Intent that was used to re-launch it"

This solves the problem I was trying to figure out, that the Intent wasn't being passed to onCreate when the application was already running, because onCreate() wasn't called.

Comments