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);
我有意向通知。当您单击通知时,它会启动活动但是在MainActivity中我不知道如何使用intent。我也假设一旦我知道如何在主要活动中读取Intent,我就可以使用putExtra()来传递数据。
由于
答案 0 :(得分:1)
在您开始的活动中,您可以使用:
Bundle extras = getIntent().getExtras();
if(extras !=null) {
//read extras (extras.getString/getBoolean/etc)
}
...是的,您需要使用putExtra
将数据传递给Intent
。
答案 1 :(得分:0)
您在意图中设置的额外内容必须由getIntent().getExtras()
检索savedInsanceState
更多是关于检索状态。