Android 我有一个带有附加意图的通知,我如何将数据传递给意图活动?
我有一份意向通知。当您单击通知时,它将启动活动,但是在MainActivity中,我不知道如何使用该意图。我还假设,一旦我知道如何读取主要活动中的意图,我就可以使用putExtra()传递数据Android 我有一个带有附加意图的通知,我如何将数据传递给意图活动?,android,Android,我有一份意向通知。当您单击通知时,它将启动活动,但是在MainActivity中,我不知道如何使用该意图。我还假设,一旦我知道如何读取主要活动中的意图,我就可以使用putExtra()传递数据 感谢您在您开始的活动中使用: notificationManager = (NotificationManager) ctx.getSystemService(Context.NOTIFICATION_SERVICE); note = new Notification(android.R.drawable
感谢您在您开始的活动中使用:
notificationManager = (NotificationManager) ctx.getSystemService(Context.NOTIFICATION_SERVICE);
note = new Notification(android.R.drawable.btn_star_big_on, "Ticker Text", System.currentTimeMillis() );
note.defaults |= Notification.DEFAULT_SOUND;
note.defaults |= Notification.DEFAULT_VIBRATE;
note.defaults |= Notification.FLAG_AUTO_CANCEL;
Intent notificationIntent = new Intent(ctx, com.mindfsck.PossAff.MainActivity.class);
//Intent notificationIntent = new Intent();
notificationIntent.setAction(Intent.ACTION_MAIN);
notificationIntent = notificationIntent.setFlags(Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
contentIntent = PendingIntent.getActivity(ctx, 0, notificationIntent, 0);
note.setLatestEventInfo(ctx, "contentTitle", "contentText", contentIntent);
note.number = 1; //Just created notification so number=1. Remove this line if you dont want numbers
notificationManager.notify(notif_ID,note);
…是的,您需要使用
putExtra
将数据传递给Intent
您在Intent中设置的额外数据必须由getIntent()检索。savedInsanceState
更多的是检索状态
Bundle extras = getIntent().getExtras();
if(extras !=null) {
//read extras (extras.getString/getBoolean/etc)
}