お知らせからランチ活動。
Intent notificationIntent = new Intent(context, MainActivity.class);
notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP );
notificationIntent.putExtra(GCM_EXTRA_ID, id);
PendingIntent intent = PendingIntent.getActivity(context, 0, notificationIntent, PendingIntent.FLAG_CANCEL_CURRENT);
notification.setLatestEventInfo(context, title, message, intent);
notification.flags |= Notification.FLAG_AUTO_CANCEL;
notification.defaults |= Notification.DEFAULT_SOUND;
notificationManager.notify(0, notification);
アクティビティが破棄された場合、インテントは新しいアクティビティを作成し、oncreate アクティビティでこのコードを呼び出します
Bundle extras = getIntent().getExtras();
if(extras != null){
if(extras.containsKey(GCMIntentService.GCM_EXTRA_ID))
{
int id = extras.getInt(GCMIntentService.GCM_EXTRA_ID);
Toast.makeText(this, "GCM_EXTRA_ID ACTIVITY ON CREATE:" + Integer.toString(id) , Toast.LENGTH_LONG).show();
dbClassItem = new DBClass(this);
db = dbClassItem.getWritableDatabase();
DBClass.setLocateValue(db, id);
db.close();
getIntent().putExtra(GCMIntentService.GCM_EXTRA_ID, 0);
}
}
戻るボタンでアクティビティを閉じて、もう一度アクティビティを開始すると、そのインテントにはキーが追加されていますGCMIntentService.GCM_EXTRA_ID
(これは公開されている静的文字列です)。
次のアプリの起動のために、このエクストラをクリアまたは交換するにはどうすればよいですか? getIntent().removeExtra()
、getIntent().getExtras().clear(),getIntent().putExtra(GCMIntentService.GCM_EXTRA_ID, 0)
動作しません。私に何ができる ?活動には android:launchMode ="singleTop"
鍵があります。