【问题标题】:How to handle status bar notification?如何处理状态栏通知?
【发布时间】:2013-01-22 05:38:59
【问题描述】:

我有三个屏幕,例如登录,第二个和第三个。根据我的条件,我生成状态栏通知。如果用户单击通知,我想显示第三个屏幕。它工作正常。但是当我直接重新启动应用程序时,第三个屏幕来了。单击通知时,我想显示第三个屏幕。否则我的第一个屏幕应该是登录页面。

我可以使用以下代码显示通知

public void showNotification() 
    {
        NotificationManager notificationManager = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);
        Notification notification = new Notification(R.drawable.ic_launcher, "A New Message!", System.currentTimeMillis());


    Intent notificationIntent = new Intent(Preferences.this,PendingOffers.class);

    PendingIntent pendingIntent = PendingIntent.getActivity(Preferences.this, 0, notificationIntent, 0);

    notification.setLatestEventInfo(Preferences.this,"sample notification", "notificationMessage", pendingIntent);

    notification.flags |= Notification.FLAG_AUTO_CANCEL;

    notificationManager.notify(0, notification); 
};

【问题讨论】:

  • 请输入一些代码,说明当用户点击通知时如何调用第三屏。所以我们可以为您提供帮助。

标签: android notifications


【解决方案1】:

您可以为意图设置标志, 例如

FLAG_ACTIVITY_NO_HISTORY

参考:http://developer.android.com/reference/android/content/Intent.html#FLAG_ACTIVITY_NO_HISTORY 也检查其他标志。

【讨论】:

    【解决方案2】:
    Intent intent = new Intent(this, some.class)
    intent.putExtra("yourpackage.notifyId", id);
    PendingIntent contentIntent = PendingIntent.getActivity(this, 1, intent, 0);
    

    更多信息请查看link

    【讨论】:

      【解决方案3】:

      您提出的问题与您使用的通知无关。用户返回到您的应用程序中的第三个Activity,因为当您的应用程序没有真正停止,而只是在后台暂停时,用户默认返回到他在单击启动器图标时查看的最后一个活动再次。

      此问题有多种解决方案,具体取决于您的具体情况。如果用户永远不应该返回到第三个Activity,您可以在您的清单中为该活动设置android:noHistory=“true”,请参见此处:How does android:noHistory=“true” work?

      如果只有登录用户应该能够返回到第三个Activity,您可以只存储如果用户登录在SharedPreferences。当第三个Activity 启动时,您检查该值并使用Intent.FLAG_ACTIVITY_CLEAR_TOPIntent 标志将用户重定向到登录活动。这将在您的 Login-Activity 上次执行后从堆栈中清除所有 Activities

      【讨论】:

        猜你喜欢
        • 2017-09-21
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多