Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/hibernate/5.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 getLongExtra始终使用PendingEvent返回默认值_Android_Android Intent_Bundle_Android Pendingintent_Extras - Fatal编程技术网

Android getLongExtra始终使用PendingEvent返回默认值

Android getLongExtra始终使用PendingEvent返回默认值,android,android-intent,bundle,android-pendingintent,extras,Android,Android Intent,Bundle,Android Pendingintent,Extras,我想使用类似这样的PendingEntant传递一个长值 Intent intentForPending = new Intent(context, NewBlaBlaActivity.class); long courseId = 15252; intentForPending.putExtra("courseId", courseId); intentForPending.putExtra("isFromPushNotification", true); PendingIntent con

我想使用类似这样的PendingEntant传递一个长值

Intent intentForPending = new Intent(context, NewBlaBlaActivity.class);
long courseId = 15252;
intentForPending.putExtra("courseId", courseId);
intentForPending.putExtra("isFromPushNotification", true);

PendingIntent contentIntent = PendingIntent.getActivity(context, 0, intentForPending, 0);

NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(
        context).setSmallIcon(R.drawable.appicon)
        .setContentTitle("BlaBla")
        .setStyle(new NotificationCompat.BigTextStyle().bigText(message))
        .setContentText(message)
        .setAutoCancel(true);


mBuilder.setContentIntent(contentIntent);
mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build());
并得到如下所示的值

Intent intent = getIntent();
if(intent.getBooleanExtra("isFromPushNotification", false)) {
    long courseId = intent.getLongExtra("courseId", 0);     
}
但我总是从意图中得到0。奇怪的是,虽然我可以从意图中使用'isFromPushNotification'键获取布尔值,但我无法从相同的意图中获取长值

这让我发疯。如您所见,这是一个PushNotification,当我点击该通知时,该代码将运行

我尝试了从stackoverflow的论坛和问题中获得的所有方法,在def上添加了L后缀,在长对象上添加了原始值。但我认为挂帐篷是件扫兴的事


我在等待你上帝般的建议。谢谢

如果要将extras与
PendingContent
一起使用,请始终在
PendingContent
工厂方法的最后一个参数中使用标志(
getActivity()
)。您可能希望指示用新的附加内容替换任何现有的
pendingent
内容。

intent.getIntExtra(“courseId”,0)返回15252?intent.hasExtra(“courseId”)返回什么?这就是上帝般的答案。谢谢