使用数据从通知启动应用程序

时间:2011-11-20 21:21:20

标签: android

我正在尝试使用C2DM在我的Android手机上触发推送通知,并让用户点击通知并在应用中启动某项活动。我怎样才能传递这些信息?

目前我正在做以下事情:

        String ns = Context.NOTIFICATION_SERVICE;
        NotificationManager mNotificationManager 
            = (NotificationManager) getSystemService(ns);

        int icon = R.drawable.notification23;

        Notification notification = new Notification(icon, tickerText, when);
        notification.flags |= Notification.FLAG_ONGOING_EVENT | Notification.FLAG_AUTO_CANCEL;  

        Context appContext = getApplicationContext();
        Intent notificationIntent = new Intent(this, RequestDialogActivity.class);          
        notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP
                | Intent.FLAG_ACTIVITY_SINGLE_TOP);
        notificationIntent.putExtra(LocationHandler.KEY_ORIGINATOR, number);
        PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);

        notification.setLatestEventInfo(appContext, contentTitle, contentText, contentIntent);

        final int id = 1;

        mNotificationManager.notify(id, notification);

我正在尝试通过在notificationIntent上调用putExtra来存储状态,但新活动始终具有null savedInstanceState Bundle。我如何传递信息?

1 个答案:

答案 0 :(得分:1)

您在意图中设置的额外内容必须由getIntent().getExtras()检索savedInsanceState更多是关于在系统关闭应用程序并且您想要恢复相同状态时检索状态用户上次看到了。

相关问题