Android addFlags不适用于PendingEvent(应为单顶模式)
如何确保活动以单端模式启动? 我不想在清单中设置启动模式,但只使用标志 我的代码怎么了?谢谢你的帮助 MainActivity.javaAndroid addFlags不适用于PendingEvent(应为单顶模式),android,android-intent,android-notifications,Android,Android Intent,Android Notifications,如何确保活动以单端模式启动? 我不想在清单中设置启动模式,但只使用标志 我的代码怎么了?谢谢你的帮助 MainActivity.java Intent intent=new Intent(this, MainActivity.class); intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP); PendingIntent pi=PendingIntent.getActivity(this
Intent intent=new Intent(this, MainActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
PendingIntent pi=PendingIntent.getActivity(this, 0,intent, 0);
if(Build.VERSION.SDK_INT>=26){
Toast.makeText(MainActivity.this, "Verision>26, id:"+id,Toast.LENGTH_SHORT).show();
NotificationChannel channel = new NotificationChannel(CHANNEL_ID, "Channel name",
NotificationManager.IMPORTANCE_HIGH);
channel.setDescription("description");
NotificationManager notificationManager = getSystemService(NotificationManager.class);
notificationManager.createNotificationChannel(channel);
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this, CHANNEL_ID)
.setSmallIcon(R.mipmap.ic_launcher)
.setContentTitle(textTitle)
.setContentText(textContent)
.setAutoCancel(true)
.setContentIntent(pi);
notificationManager.notify(id, mBuilder.build());
}
编辑
用setFlags替换addFlags对我不起作用…尝试setFlags而不是addFlags 意向意向=新意向(此,MainActivity.class); intent.setFlags(intent.FLAG\u ACTIVITY\u SINGLE\u TOP) 请检查一下Intent()的参数