tags:

views:

19

answers:

2

I have a normal notification system that looks like this:

Notification notification new Notification(
        R.drawable.alerts_notification,
        alertTitle,
        System.currentTimeMillis());
Intent intent = new Intent(mContext, MyActivity.class);
intent.setAction(MyActivity.ONE_ACTION);
PendingIntent pi = PendingIntent.getActivity(mContext, 0, intent, 0);
mNotifMan.notify(ID, notification);

Notice that I'm using ONE_ACTION as the action of the intent. What I do is verify the action on the activity and select one of the tabs (it's a TabActivity).

All that works fine if the activity is closed, because the Intent will open the activity and then I will decide what to do depending on the action in the Intent. But, if the activity is already opened, it launches a new activity. On the other hand, if I add the flag Intent.FLAG_ACTIVITY_SINGLE_TOP, the activity is not launched twice but I can't the tab is not chosen either.

So, how can choose a tab by clicking on the notification?

A: 

Have your intent open your tab activity and put an extra in it denoting the tab. When you detect action resume get a handle on your tab controller and change the tab through code.

schwiz
A: 

OK, I found how to do it... it seems I hadn misread the documentation. What I did was:

  1. Add this to the activity in the AndroidManifest.xml file: android:launchMode="singleInstance"
  2. Overwrite the onNewIntent(Intent intent) method on the activity and put there all the logic to select the tabs etc.
  3. Launch the intent with the flag Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT

@schwiz, thanks for your answer though.

Cristian
can you give me a demo or tutorial
pengwang
@pengwang what about?
Cristian
it is about this problem,tabactivity and notification.because i meet this problem.i donot know your answer,so i want to you give me a demo or tutorial.thank you
pengwang