Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/203.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通知';背景中的t_Android_Android Intent_Push Notification - Fatal编程技术网

应用程序不可用时的Android通知';背景中的t

应用程序不可用时的Android通知';背景中的t,android,android-intent,push-notification,Android,Android Intent,Push Notification,我在安卓系统中遇到了一个奇怪的通知问题。我以这种方式创建通知: NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); Intent notificationIntent = new Intent(context, MyClass.class); notificati

我在安卓系统中遇到了一个奇怪的通知问题。我以这种方式创建通知:

        NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
        Intent notificationIntent = new Intent(context, MyClass.class);
        notificationIntent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
        notificationIntent.putExtra("data", value);

        PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);
        Notification updateComplete = new NotificationCompat.Builder(context)
                .setContentTitle(title)
                .setContentText(msg)
                .setTicker(title)
                .setWhen(System.currentTimeMillis())
                .setContentIntent(contentIntent)
                .setDefaults(Notification.DEFAULT_SOUND)
                .setAutoCancel(true)
                .setSmallIcon(R.drawable.icon_notifications)
                .build();

        notificationManager.notify(100, updateComplete);
当应用程序运行时(或在后台),用户点击通知,一切正常
onNewIntent
被调用,数据在附加中。但当应用程序未运行或未在后台运行时,则不会调用
onNewIntent()
。我尝试使用
getIntent()
onCreate()
获取
intent
,但它从来没有额外的功能。当应用程序尚未运行时,是否仍有额外的功能


我的所有活动都是
singleTop

尝试设置一些操作:

notificationIntent.setAction(Long.toString(System.currentTimeMillis()));  
然后在onCreate中获得额外功能

您也可以尝试将
pendingent.FLAG\u UPDATE\u CURRENT
替换为
0