インテントを使用してデータを保存し、アプリケーションの他の場所に復元しています。私は他の場所でそれらを使用しましたが、今は期待どおりに機能していません.
public class GCMIntentService extends GCMBaseIntentService {
public GCMIntentService() {
super(ConstantsGCM.GCM_SENDER_ID);
}
@Override
protected void onMessage(Context context, Intent intent) {
...
String ns = Context.NOTIFICATION_SERVICE;
NotificationManager notManager = (NotificationManager) context.getSystemService(ns);
String room = intent.getExtras().getString(ConstantsGCM.GCM_ROOM);
Intent notIntent;
PendingIntent contIntent;
Notification notif;
notif = new Notification(icon, textStatus, time);
notIntent = new Intent(contexto,RoomsActivity2.class);
Bundle b2 = new Bundle();
b2.putString(ConstantsRooms.ROOM, room);
notIntent.putExtras(b2);
contIntent = PendingIntent.getActivity(contexto, 0, notIntent, 0);
notif.setLatestEventInfo(contexto, tittle, description, contIntent);
notif.flags |= Notification.FLAG_AUTO_CANCEL;
notManager.notify((int)(Math.random()*1000), notif);
このコードは、通知が来るときに実行されます。この通知をクリックすると、Activity RoomsActivities2.class が実行されます。ここでは、このコードを呼び出します。
public String getMessageString(String cod){
String result = "";
bundle = getIntent().getExtras();
if (bundle != null){
result = bundle.getString(cod);
}
return result;
}
しかし、インテントに保存された最後のデータを取得できませんでした。何が悪いの?私はそれを正しく使用していないと思います。アクティビティからデータを取得できないのはなぜですか?
それが起こっていると私が思うことは次のとおりです。アプリケーションは多くの通知を受け取り、最初の通知は正しく機能します。しかし、さらに多くの通知を受け取り続けると、データはオーバーライドされず、コードをデバッグするときに別のデータを設定していますが、常に最初の通知を取得します。