我尝试了stackOverflow中的所有建议 - 没有任何帮助。 通知工作正常,它只是以某种方式丢失了它。
这是我的PendingIntent:
NotificationManager notificationManager = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
Intent intent = new Intent(this, LoginActivity.class);
// Intent intent = new Intent().setClass(this, LoginActivity.class);
intent.putExtra(Constants.KEY_BUNDLE_MESSAGE_FROM_NOTIFICATION,true);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
//intent.setAction("dummy");
PendingIntent contentIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
NotificationCompat.Builder noBuilder = new NotificationCompat.Builder(this)
.setSmallIcon(R.mipmap.ic_launcher)
.setContentTitle(title)
.setContentText(text)
/* .setStyle(new NotificationCompat.BigTextStyle()
.bigText(message))*/
.setAutoCancel(true)
.setContentIntent(contentIntent);
notificationManager.notify(0, noBuilder.build());
1)向Intent添加动作:intent.setAction(“dummy”);
2)将setClass添加到Intent:.setClass(this,LoginActivity.class);
3)Pending intent尝试了所有标志:PendingIntent.FLAG_UPDATE_CURRENT / FLAG_CANCEL_CURRENT / FLAG_ONE_SHOT / 0
4)尝试在“onNewIntent”和“onCreate”中收到额外内容
接收活动中的额外内容始终为假
@Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
Log.d(TAG, "im in login from notification! "+ intent.hasExtra(Constants.KEY_BUNDLE_MESSAGE_FROM_NOTIFICATION));
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
Intent intent = getIntent();
Log.d(TAG, "im in login from notification! "+ intent.hasExtra(Constants.KEY_BUNDLE_MESSAGE_FROM_NOTIFICATION));
}
任何想法? 谢谢!
答案 0 :(得分:0)
在onNewIntent
添加:setIntent(intent)