Android 当我单击通知时,我的Intent.Extras始终为空。我如何获得意向数据?

Android 当我单击通知时,我的Intent.Extras始终为空。我如何获得意向数据?,android,android-intent,notifications,xamarin,android-notifications,Android,Android Intent,Notifications,Xamarin,Android Notifications,当我查看通知时,无法获取意图的附加数据。以下是我如何构建通知,以及我传递到通知中的意图数据。有什么问题吗?我看到过其他类似的例子,似乎也能奏效 protected override void OnMessage(Context context, Intent intent) { // irrelevant stuff removed string title = "Notification"; string

当我查看通知时,无法获取意图的附加数据。以下是我如何构建通知,以及我传递到通知中的意图数据。有什么问题吗?我看到过其他类似的例子,似乎也能奏效

    protected override void OnMessage(Context context, Intent intent)
    {
            // irrelevant stuff removed

            string title = "Notification";
            string message = "The Notification Message";

            Bundle valuesForActivity = new Bundle();
            valuesForActivity.PutInt("panelId", (int)panelId);

            Intent pendingIntent = new Intent(context, typeof (TabContainer));
            pendingIntent.PutExtras(valuesForActivity);
            pendingIntent.SetFlags(ActivityFlags.SingleTop);
            pendingIntent.PutExtra("panelId", (int)panelId);

            //neither PendingIntentFlags.CancelCurrent or PendingIntentFlags.UpdateCurrent works
            PendingIntent resultPendingIntent = PendingIntent.GetActivity(context, 0, pendingIntent, PendingIntentFlags.CancelCurrent);
            //PendingIntent resultPendingIntent = PendingIntent.GetActivity(context, 0, pendingIntent, PendingIntentFlags.UpdateCurrent);

            var builder = new NotificationCompat.Builder(context);
            builder.SetContentTitle(title);
            builder.SetAutoCancel(true);
            builder.SetSmallIcon(Resource.Drawable.icon24);
                builder.SetLargeIcon(BitmapFactory.DecodeStream(context.Resources.OpenRawResource(Resource.Drawable.icon96)));
                builder.SetContentText(message);
            builder.SetContentIntent(resultPendingIntent);
            builder.SetTicker(title);
            builder.SetVibrate(new long[] { 100, 200, 300 });

            var notificationManager = GetSystemService(Context.NotificationService) as NotificationManager;
            notificationManager.Notify(1, builder.Build());
    }
然后在TabContainer活动中,我从来没有需要的数据:

public class TabContainer : TabActivity
{
    protected override void OnResume()
    {
        base.OnResume();

        int panelId = Intent.GetIntExtra("panelId", 0); // always 0

        var extras = Intent.Extras; // always null

    }
}
这起到了作用:

public class TabContainer : TabActivity
{
    protected override void OnNewIntent(Intent intent)
    {
        base.OnNewIntent(intent);

        try
        {
            var panelId = intent.GetIntExtra("panelId", 0);

            // do the things I need with panelId.
        }
        catch (Exception ex)
        {
            DealWithError(ex);
        }
    }
}

某处应该有个帐篷?(至少在实际的android中有)什么是panelId?检查它是否可以是int,而将intent
OnNewIntent
作为解决方案。我已经在TabContainer中重写了它,它正在启动,
Intent
对象包含我需要的数据。酷。请回答您自己的问题并接受该答案,以便将此问题从“未回答”列表中删除。