Search code examples
androidandroid-pendingintentandroid-tablayout

Open specific tab from Pending Intent


I am trying to set the focus on the specific tab after click on Push Notification I am unable to redirect it, here is my code

 Intent intent_chat=new Intent(this, HomeChatFragment.class);
 pendingIntent=PendingIntent.getActivity(this,0,intent_chat,PendingIntent.FLAG_UPDATE_CURRENT);

Any kind of guidance will be great, thanks!


Solution

  • Intent intent_chat=new Intent(this, HomeChatFragment.class);
    intent.putExtra("someFlag", 2); //tab position to open
    pendingIntent=PendingIntent.getActivity(this,0,intent_chat,PendingIntent.FLAG_UPDATE_CURRENT);
    

    and in your HomeChatFragment.java do this:

    @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            ...
            ...
            int i;
            if(getIntent() != null) {
                i = getIntent().getIntExtra("someFlag", -1);
           }
           if(i != -1) {
               yourViewPager.setCurrentItem(i);
           }
       }