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
Asked
Active
Viewed 163 times
0

Pankaj
- 7,908
- 6
- 42
- 65

ravi chandra
- 60
- 1
- 9
-
You just want to highlight or show its content also??? – Pankaj Jun 10 '15 at 05:26
-
Both first need to highlight then showing contents – ravi chandra Jun 10 '15 at 05:27
-
check out [this link](http://stackoverflow.com/a/24836021/2715073) might help you – Pankaj Jun 10 '15 at 05:49
2 Answers
0
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 ;)

Ritvik Vyas
- 42
- 1
0
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.

Pankaj
- 7,908
- 6
- 42
- 65
-
Yes i am doing like this but Content is displaying in particular tab but it is not highlighting – ravi chandra Jun 10 '15 at 05:46
-
check out [this link](http://stackoverflow.com/a/24836021/2715073) might help you – Pankaj Jun 10 '15 at 05:50
-
tabs.getTabHost().setCurrentTab(2); for this just set the colour for tab 2 and update the code it may solve my problem – ravi chandra Jun 10 '15 at 05:54
-
It is solved but my problem if notification arrives how to refresh the activity..? if refresh the activity my problem will solve 100% – ravi chandra Jun 10 '15 at 06:17