丢失在PendingIntent字段中

时间:2011-06-18 19:54:14

标签: android notifications android-intent android-pendingintent

我对PendingIntent有点失落。

据我所知,这是给操作系统执行稍后(因此待处理)操作的令牌。

我有一项推出服务的活动。该服务偶尔会创建一个通知。 我最想做的就是将活动带到前线。

我不确定我在哪里以及如何创建以及向谁发送PendingActivity。

  • 如果我在Activity中创建它,我需要将它发送到服务 - 如何?
  • 如果我在服务中创建它,上下文将如何调用活动?这些是一样的吗? - 我虽然这些是相同的,就像操作系统的工作方式一样,但它对我不起作用。

以下是一些代码行

这不起作用btw StartService获取Intent。 此代码在我的活动中

        Intent intent = new Intent(this, NeglectedService.class);

    // The PendingIntent to launch our activity if the user selects this notification
    PendingIntent contentIntent = PendingIntent.getActivity(this, 
            0,
            intent, 
            PendingIntent.FLAG_ONE_SHOT);

    startService(contentIntent);

所以,正确的是

Intent intent = new Intent(this, NeglectedService.class);
startService(contentIntent);

所以我想在我的服务中制作待定意图,但这对我不起作用,因为我不确定如何重用/使用意图

Notification notification = new Notification(R.drawable.icon, 
            extra, 
            System.currentTimeMillis());

    PendingIntent contentIntent = PendingIntent.getActivity(this, 
            0,
            intent, // not sure what intent to use here !!!!
            PendingIntent.FLAG_ONE_SHOT);

    notification.setLatestEventInfo(getApplicationContext(), contentTitle, contentText, contentIntent);
    notification.defaults |= Notification.DEFAULT_SOUND;
    notification.defaults |= Notification.DEFAULT_LIGHTS;
    notification.defaults |= Notification.FLAG_INSISTENT;

    mNotificationManager.notify(id, notification);

1 个答案:

答案 0 :(得分:1)

解决 需要做的是使用intent中的Neglected.class。

相关问题