当我收到推送通知并单击它时,我的应用程序打开并在空白屏幕上停止,只有空白工具栏。
它并不总是发生,仅当应用长时间在后台运行且未被系统杀死时才会发生。 单击正在运行的应用程序并选择我的应用程序仅有助于继续加载
当应用终止运行并从寒冷中打开时,它可以正常工作。当应用程序最近合拢时,它也可以正常工作,并可以通过推送打开
谢谢
Activity attributes:
[MvxActivityPresentation]
[Activity(
AlwaysRetainTaskState = true,
Label = "MyPushApp",
LaunchMode = LaunchMode.SingleTop,
Theme = "@style/Theme.MyTheme",
ScreenOrientation = ScreenOrientation.User)]
public class MainActivity : ExtendedDrawerActivity<MenuVM>, ITabletActivity
Activity OnResume():
protected override void OnResume()
{
base.OnResume();
if (ViewModel.InitializeTask.IsSuccessfullyCompleted && CheckIntentForPushNotification())
{
ViewModel.PushReceived = false;
OpenPushNotification();
}
CheckIntentForPushNotification():
protected bool CheckIntentForPushNotification()
{
return Intent != null && Intent.Extras != null && (Intent.HasExtra(MyFirebaseMessagingService.NotificationBodyTag) || Intent.HasExtra(CheckNotificationsService.LocalNotificationTag));
}
OpenPushNotification():
private void OpenPushNotification()
{
if (ViewModel.PushReceived || Intent == null)
{
_log.Info("ViewModel.PushReceived || Intent == null");
return;
}
if (Intent.HasExtra(MyFirebaseMessagingService.NotificationBodyTag))
{
string notificationText = Intent.GetStringExtra(MyFirebaseMessagingService.NotificationBodyTag);
string objIds = Intent.GetStringExtra(MyFirebaseMessagingService.ObjectIdTag);
string objType = Intent.GetStringExtra(MyFirebaseMessagingService.ObjectTypeTag);
string objSubtype = Intent.GetStringExtra(MyFirebaseMessagingService.ObjectSubtypeTag);
string moduleType = Intent.GetStringExtra(MyFirebaseMessagingService.ModuleTypeTag);
string notificationType = Intent.GetStringExtra(MyFirebaseMessagingService.NotificationTypeTag);
string folderId = Intent.GetStringExtra(MyFirebaseMessagingService.FolderIdTag);
List<int> ids = objIds?.Split(',')?.Select(id => int.Parse(id))?.ToList();
Mvx.IoCProvider.Resolve<IMvxMessenger>().Publish(new MainPushMessage(this)
{
Text = notificationText,
AppLaunchedByNotification = _startWithNotification,
NotificationTypeId = string.IsNullOrEmpty(notificationType) ? 0 : Int32.Parse(notificationType),
FolderId = string.IsNullOrEmpty(folderId) ? 0 : Int32.Parse(folderId),
ObjectIds = ids ?? new List<int>(),
ObjectType = objType,
ObjectSubtype = objSubtype,
});
}
if (Intent.HasExtra(CheckNotificationsService.LocalNotificationTag))
{
Mvx.IoCProvider.Resolve<IMvxMessenger>().Publish(new MainPushMessage(this)
{
IsLocalNotification = true
});
}
Intent = null;
}
Activity OnNewIntent():
protected override void OnNewIntent(Intent intent)
{
base.OnNewIntent(intent);
Intent = intent;
}