So it was pretty easy. Hope I can help someone else see this too.
I am sending the action of this notify function. I am adding this action to my intent to trigger the action. In my case, I open the launch because all fragments are loaded from this action based on what the user is doing. Therefore, I set the action using setAction , and I use this action in the action, as shown below.
My Notifications.java class has changed to this:
public static void notify(Context context, String message, String action) { action = action.toUpperCase();
And then in my activity , from where I load the fragments, I get the action and filter it:
Intent intent = getIntent(); try{ String action = intent.getAction().toUpperCase(); if(action != null){ if(action.equalsIgnoreCase(getResources().getString(R.string.notification_action_friend))){ goFrag(getResources().getInteger(R.integer.FRAG_A_INT)); } if(action.equalsIgnoreCase(getResources().getString(R.string.notification_action_article))){ goFrag(getResources().getInteger(R.integer.FRAG_B_INT)); } if(action.equalsIgnoreCase(getResources().getString(R.string.notification_action_points))){ goFrag(getResources().getInteger(R.integer.FRAG_C_INT)); } if(action.equalsIgnoreCase(getResources().getString(R.string.notification_action_redeemable))){ goFrag(getResources().getInteger(R.integer.FRAG_D_INT)); } if(action.equalsIgnoreCase(getResources().getString(R.string.notification_action_dance))){ goFrag(getResources().getInteger(R.integer.FRAG_E_INT)); } }else{ Log.d(TAG, "Intent was null"); } }catch(Exception e){ Log.e(TAG, "Problem consuming action from intent", e); }
In my goFrag function goFrag I replace the fragment if the required fragment is still in memory (which means that the user was there before and it has not yet been destroyed), or I create the required new fragment.
source share