Reputation: 26668
I was trying to implement push notifications in android and below is my receiver
code
public class MessageReceiver extends BroadcastReceiver {
public void onReceive(Context ctx, Intent intent) {
Intent myIntent = new Intent(ctx, MainActivity.class);
myIntent.putExtra("skipList", true);
PendingIntent pendingIntent = PendingIntent.getActivity(
ctx, 0, myIntent, 0);
NotificationCompat.Builder mBuilder =
new NotificationCompat.Builder(ctx)
.setSmallIcon(R.drawable.ic_launcher)
.setContentTitle(intent.getExtras().getString("subject"))
.setContentText(intent.getExtras().getString("cover"))
.setContentIntent(pendingIntent);
mBuilder.setSound(Settings.System.DEFAULT_NOTIFICATION_URI);
NotificationManager mNotificationManager = (NotificationManager)ctx.getSystemService(Context.NOTIFICATION_SERVICE);
mNotificationManager.notify(1, mBuilder.build());
}
}
So from the above code i was adding the data skipList = True
to intent myIntent
I just want to retrieve this data in my MainActivity.java
file as below
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Intent iin= getIntent();
Log.v("<<<<<<<<<<<<iiiiiiiii>>>>>>>>>>>>>>>>",iin.toString());
Bundle b = iin.getExtras();
Log.v("<<<<<<<<<<<<bbbbbbbb>>>>>>>>>>>>>>>>",b.toString());
String wow = b.getString("skipList");
Log.v("<<<<<<<<<<<<wowowowoow>>>>>>>>>>>>>>>>",wow.toString());
}
But i was unable to get the data from the intent what am i doing wrong ?
Upvotes: 0
Views: 78
Reputation: 6169
You are using putExtra with a boolean parameter, but you are retrieving it as a String.
You need to get it using the getBooleanExtra()
method.
Just replace this line:
String wow = b.getString("skipList");
with this:
boolean wow = b.getBooleanExtra("skipList");
Upvotes: 1
Reputation: 488
In code your passing boolean data through intent,but getting it as a string: try like this,
boolean isSkipList = getIntent().getExtras().getBoolean("skipList");
(or)
replace below line:
String wow = b.getString("skiplist");
with this line:
boolean wow = b.getBoolean("skiplist");
Upvotes: 0
Reputation: 418
you should write
boolean wow = b.getBooleanExtras("skipList");
or
myIntent.putExtra("skipList", "true");
Upvotes: 0
Reputation:
You are passing boolean value so you should read boolean to use following code
getIntent().getBooleanExtra("skipList", defaultValue);
This may help you.
Upvotes: 0