【问题标题】:Pending Intent in Notification not working Android通知中的待处理意图不起作用Android
【发布时间】:2017-12-19 13:56:49
【问题描述】:

我的未决意图未按预期工作。

问题是:点击通知时,它会重定向到 Splash Activity,这是我的应用程序启动器 Activity,以下是我创建通知的代码。

  Intent intent = new Intent(this, QuickTasks.class).putExtra("NOTIFICATION", 1);
  intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    PendingIntent resultIntent = PendingIntent.getActivity(this, 0, intent,
            PendingIntent.FLAG_ONE_SHOT);

    Uri notificationSoundURI = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    NotificationCompat.Builder mNotificationBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.mipmap.ic_launcher)
            .setContentTitle("Suvi")
            .setContentText(messageBody)
            .setAutoCancel(true)
            .setSound(notificationSoundURI)
            .setContentIntent(resultIntent);

    NotificationManager notificationManager =
            (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

    notificationManager.notify(0, mNotificationBuilder.build());     

请在这方面帮助我,我在这里使用了许多可用的资源,但没有一个有效。任何帮助都会很有意义。

【问题讨论】:

  • pending intent not working as to be expected to work 是什么意思?解释行为以及例外行为
  • 我想打开 QuickTasks.class 而不是打开启动画面
  • 您确定QuickTasks.class 与启动活动无关,请在没有FLAG_ACTIVITY_CLEAR_TOP 的情况下尝试,如果您仍然无法看到QuickTasks.class,那么您的代码中存在逻辑问题
  • 您的 QuickTask 在开始时是否有特殊行为?谁可能会自动将您重定向到您的启动活动?
  • Splash Activity 是我的主要活动

标签: java android android-intent android-notifications android-pendingintent


【解决方案1】:

一般来说,当您想从通知开始活动时,有两种情况:

  1. 常规活动: 您正在启动一个 Activity,它是应用程序正常工作流程的一部分。
  2. 特别活动: 如果它是从通知启动的,用户只会看到这个 Activity。从某种意义上说,Activity 通过提供在通知本身中难以显示的信息来扩展通知。

请参考以下链接。
Preserving Navigation when Starting an Activity
希望对您有所帮助。

【讨论】:

    猜你喜欢
    • 2014-01-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-12-04
    • 1970-01-01
    相关资源
    最近更新 更多