How to highlight a Tab when Notification received

193 views Asked by At

I have implemented Tab host with the Notification. Now My problem is: there are 3 tabs like Food, Health and Service. If i receive a Food Notification How to highlight the Food Tab automatically

2

There are 2 answers

4
Pankaj On BEST ANSWER

Do like this :

First Step: Create a broadcast receiver which you can call when you click on notification

Intent notificationIntent = new Intent(context,
                PushNotificationBroadcastReceiver.class); // this is the broadcast receiver which will be called 
                PendingIntent resultPendingIntent = PendingIntent.getBroadcast(context,
                1, notificationIntent, 0);

Second Step: in onReceive() method put below line:

TabActivity tabs = (TabActivity) getParent();
    tabs.getTabHost().setCurrentTab(2);  //2 means the position of tab which you want to show

That's it.

0
Ritvik Vyas On

For switching to some other tab than the default one you need to put this code on the onClick or whatever triggers the action

TabActivity tabs = (TabActivity) getParent(); tabs.getTabHost().setCurrentTab(x);

Just replace x with the tab which you would like to navigate to and make sure to change the variable names and class names as per your project. Hope it helps you ;)