Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/189.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android addFlags不适用于PendingEvent(应为单顶模式)_Android_Android Intent_Android Notifications - Fatal编程技术网

Android addFlags不适用于PendingEvent(应为单顶模式)

Android 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

如何确保活动以单端模式启动? 我不想在清单中设置启动模式,但只使用标志

我的代码怎么了?谢谢你的帮助

MainActivity.java

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()的参数