0

我在我们的应用程序中使用推送通知,当我在通知中心收到推送通知时,如果我单击该通知,它会正确重定向到该特定的 html 页面。但是当我收到多个推送通知时,如果我单击除第一个通知之外的任何其他通知,它将不会重定向,只有消息首先出现在通知中心列表中才会重定向。如何重定向通知中心android中的每条消息。下面是用于在android中重定向的代码。

public void onCreate(Bundle savedInstanceState) {       
    super.onCreate(savedInstanceState);             
    Bundle extras = getIntent().getExtras();        
    if (extras != null) {                                   
        super.loadUrl("file:///android_asset/www/homePage.html");       
        NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
        notificationManager.cancelAll();
    }
}
4

1 回答 1

2

问题是单击第一个通知后您的活动已经创建,因此单击第二个通知时不会调用 onCreate() 。

您需要android:launchMode="singleTop"在 AndroidManifest.xml 中为您的活动设置,并覆盖 onNewIntent。

有关详细信息,请参阅Activity#onNewIntent

于 2012-12-07T11:23:29.360 回答