Search code examples
javaandroidandroid-tabhostandroid-notifications

How to highlight a Tab when Notification received


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


Solution

  • 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.