我遇到问题我的MainActivity可以通过3种方式创建: 1)标准发布App 2)来自服务 3)从通知点击。 我如何检查它何时从通知点击开始?
通知代码:
private void createNotification()
{
Log.d("service createNotification",MainActivity.TAG);
Context context = getApplicationContext();
Intent notificationIntent = new Intent(this,MainActivity.class);
intent.putExtra(AppNames.IS_NOTIFICATION_INTENT,true);
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0,
notificationIntent, Intent.FLAG_ACTIVITY_NEW_TASK);
NotificationCompat.Builder builder = new NotificationCompat.Builder(context)
.setContentTitle(this.getString(R.string.notification_title))
.setContentText(this.getString(R.string.notification_text))
.setContentIntent(pendingIntent)
.setSmallIcon(R.drawable.ic_launcher);
getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(AppNames.APP_NOTIFICATION, builder.getNotification());
}
答案 0 :(得分:7)
添加
intent.putExtra("started_from","notification");
从通知中启动意图的代码,与其他startActivity调用相同的内容只是更改值,然后在您的活动中
String startedFrom = getIntent().getStringExtra("started_from");