小编Jar*_*d L的帖子

关闭的应用程序未调用 Xamarin Android OnNewIntent

什么是工作

我已经使用以下 Xamarin 指南为 Xamarin Forms 应用程序的 Android 端实现了推送通知:

https://developer.xamarin.com/guides/android/application_fundamentals/notifications/remote-notifications-with-gcm/

这很有效,我们正确地在应用程序运行时和在后台调用 OnNewIntent。然后我们调用我们的方法来处理推送通知的意图,一切都很好。

protected override void OnNewIntent(Intent intent)
{
    base.OnNewIntent(intent);
    GoogleListenerService.ReceivedRemoteNotification(intent);
}
Run Code Online (Sandbox Code Playgroud)

问题是什么

如果我们关闭应用程序,触发推送通知,然后单击推送通知,应用程序似乎不会调用 OnNewIntent,而是会像单击应用程序图标(调用 OnCreate)一样启动应用程序。

尝试了什么

我尝试实施的主要解决方法概述如下:

  1. 未调用 Android OnNewIntent

Xamarin 只有一个 GetIntent 方法,需要字符串 URL 输入,并使用以下结果在空数据中。

Intent intent = new Intent(this, typeof(MainActivity));
Bundle data = intent.Extras;
Run Code Online (Sandbox Code Playgroud)
  1. 未调用 onNewIntent

在第二篇文章中,我们的意图服务、MainActivity.cs 文件和清单文件中 LaunchMode = SingleTop 的所有更改都没有导致行为发生任何变化。

编辑

推送通知总是被接收并且 OnMessageReceived 总是被调用,无论应用程序是在后台还是完全关闭。此外, OnNewIntent 在应用程序处于后台时接收挂起的意图,而不是在它关闭时。

this.Intent.Extras;
Run Code Online (Sandbox Code Playgroud)

始终显示为 null(当前位于 OnResume 方法中)。

android-intent xamarin.android xamarin

7
推荐指数
1
解决办法
2280
查看次数

标签 统计

android-intent ×1

xamarin ×1

xamarin.android ×1