Ho scritto un codice nel mio GCMIntentservice che invia notifiche push a molti utenti. Io uso NotificationManager che chiamerà la classe DescriptionActivity quando si fa clic sulla notifica. Anch'io mando l'event_id formano il GCMIntentService al DescriptionActivityputExtra che utilizza l'intent in sospeso non funzionante
protected void onMessage(Context ctx, Intent intent) {
message = intent.getStringExtra("message");
String tempmsg=message;
if(message.contains("You"))
{
String temparray[]=tempmsg.split("=");
event_id=temparray[1];
}
nm= (NotificationManager)getSystemService(NOTIFICATION_SERVICE);
intent = new Intent(this, DescriptionActivity.class);
Log.i("the event id in the service is",event_id+"");
intent.putExtra("event_id", event_id);
intent.putExtra("gcmevent",true);
PendingIntent pi = PendingIntent.getActivity(this,0, intent, 0);
String title="Event Notifier";
Notification n = new Notification(R.drawable.defaultimage,message,System.currentTimeMillis());
n.setLatestEventInfo(this, title, message, pi);
n.defaults= Notification.DEFAULT_ALL;
nm.notify(uniqueID,n);
sendGCMIntent(ctx, message);
}
Qui l'event_id che sto ricevendo nel metodo di cui sopra è corretto cioè ottengo sempre quello aggiornato. Ma nel seguente codice (DescriptionActivity.java):
intent = getIntent();
final Bundle b = intent.getExtras();
event_id = Integer.parseInt(b.getString("event_id"));
L'event_id qui è sempre "5". Non importa cosa ho inseritoExtra nella classe GCMIntentService, l'event_id che ottengo è sempre 5. Qualcuno può indicare il problema? È a causa dell'intenzione in sospeso? Se sì, allora come dovrei gestirlo?
Grazie mille, ha funzionato :) – Nemin
Risposta stupenda! Grazie. –
se non è chiaro: PendingIntent pi = PendingIntent.getActivity (this, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT); – Alecs