Skip to content Skip to sidebar Skip to footer

Intent.getextras() Always Returns Null

I'm trying to run an activity through a notification and event onCreate I would like to 'redirect'. To this add a thought on information in the Intent class. An important feature i

Solution 1:

I'm going to lean out the window and guess that your problem is here:

PendingIntentpendingIntent= PendingIntent.getActivity(context, 0, intent, 0);

You are passing intent to getActivity() and expecting that you will get back a PendingIntent that matches your Intent and includes your extras. Unfortunately, if there is already a PendingIntent floating around in the system that matches your Intent (without taking into consideration your Intent extras) then getActivity() will return you that PendingIntent instead.

To see if this is the problem, try this:

PendingIntentpendingIntent= PendingIntent.getActivity(context, 0, intent,
                    PendingIntent.FLAG_UPDATE_CURRENT);

This says that if there is already a PendingIntent that matches your Intent somewhere in the system that it should replace the extras with the ones in your intent parameter.

Solution 2:

(1) Check here to make sure you are using the put/get extras correctly as I don't see the code where you are adding data the intent.

(2) It looks like you are not calling get intent and get extra and, as a result, not actually getting anything from the bundle (assuming that information extists). If you are checking for a boolean value you should get the data you place in the bundle as follows:

Bundle bundle = getIntent().getExtras();

if (bundle.getBooleanExtra("WHATEVER"){
   //whatever you want to do in here
} 

Post a Comment for "Intent.getextras() Always Returns Null"