tags:

views:

178

answers:

2

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?

A: 

Hello,

I hope you already check the docs on "How to create notifications" and "How to start Activity from notification" - if not, just check it) So as for activating particular tab from Notification, I advice you to use "extras" in your PendingIntent. just put the number, for example, of particular tab in extras in intent, and when 'onCreate()' in Activity will be called, just fetch it from Intent(in Activity call getIntent()) and just setCurrentTab(number); in tabHost.

I'm sorry for my english) hope this would help.

ponkin
This works fine for a TabAtivity that is not already running. If it's running and in the background, the Intent will never get passed to onCreate(). It just seems to refocus the TabActivity, but the Intent is never passed to it anywhere.
synic
A: 

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.

synic