I'm using GCM as service for push notifications in my app. Notification is sent when new post is added, and when user clicks on notification I want my app to open activity with that new data.
This is piece of code in GCMIntentService class for adding String extra (So activty can parse JSON from newest post:
final Intent notificationIntent = new Intent(context, Info.class);
[..]
String title = jsonObject.get("title").getAsString();
Log.d(TAG, title);
String pid = jsonObject.get("id").getAsString();
notificationIntent.putExtra("pid", pid);
Log.d(TAG, pid);
}
});
notificationIntent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP
);
PendingIntent intent = PendingIntent.getActivity(context, 0,
notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);
Returned PID string is good, but when i try to get my intent from activity
Sadly this piece of code:
Intent iz = getIntent()
pid = iz.getStringExtra("pid");
returns null.
@Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
if (intent.getExtras() != null) {
pid = intent.getStringExtra("pid");
}
}
I've tried to launch it that way, but it doesnt work either.
Any ideas how to pass string to my Activity from Pending intent?
I've googled a lot, but can't I can't find solution that would work for me,.
0 comments:
Post a Comment