我在通知onclick时遇到问题。我正在使用Firebase消息传递,我的问题是,当我单击通知时,它调用了我的OrderHelperActivity,但此后它立即调用了MainContainerActivity并显示了空白视图。有OrderHelperActivity)...这是在应用程序处于前台或后台时发生的(当应用程序启动时,它正确显示OrderHelperActivity),而另一个问题是当应用程序在后台时,它启动没有SplashScreen的应用程序是如何在之前调用SplashScreen的某种方式?
此解决方案在我的旧项目中可以使用,但是有旧的MvvmCross版本(如3.X),但是现在我创建了新项目,其中有新的MvvmCross 6.1.2。我正在使用Plac3hold3r(https://github.com/Plac3hold3r/MvxScaffolding)中的MvxScaffolding模板,因此我的项目看起来像这样(https://github.com/pinkysek/MvxNativeApp),没有此实现,但是存在MainContainerActivity的外观以及该项目的外观。
// method with notification
private void SendNotification(string title, string body, string clickAction, IDictionary<string, string> data)
{
var messageTitle = string.IsNullOrEmpty(title) ? Resources.GetString(Resource.String.app_name) : title;
var messageBody = string.IsNullOrEmpty(body) ? Resources.GetString(Resource.String.app_name) : body;
var isOrder = !string.IsNullOrEmpty(clickAction) && clickAction.Equals("ORDER");
var intent = new Intent(this, isOrder ? typeof(OrderHelperActivity) : typeof(MainContainerActivity));
intent.AddFlags(ActivityFlags.ClearTop);
if (data != null)
{
foreach (var key in data.Keys)
{
intent.PutExtra(key, data[key]);
}
}
var pendingIntent = PendingIntent.GetActivity(this, 0, intent, PendingIntentFlags.OneShot);
var notificationBuilder = new NotificationCompat.Builder(this)
.SetSmallIcon(Resource.Mipmap.ic_launcher)
.SetColor(Color.White)
.SetContentTitle($"{messageTitle}")
.SetContentText($"{messageBody}")
.SetAutoCancel(true)
.SetContentIntent(pendingIntent);
var notificationManager = NotificationManager.FromContext(this);
notificationManager.Notify(0, notificationBuilder.Build());
}
// specific activity for order notification
[IntentFilter(new[] { "ORDER" },
Categories = new[]
{
Android.Content.Intent.CategoryDefault,
})]
[MvxActivityPresentation]
[Activity(
Theme = "@style/AppTheme",
WindowSoftInputMode = SoftInput.AdjustResize | SoftInput.StateHidden,
LaunchMode = LaunchMode.SingleTop,
NoHistory = true,
ScreenOrientation = ScreenOrientation.Portrait)]
public class OrderHelperActivity : BaseActivity<OrderHelperViewModel>
{
protected override int ActivityLayoutId => Resource.Layout.activity_orderhelper;
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
if (Intent?.Extras != null)
{
foreach (var key in Intent.Extras.KeySet())
{
if (key.Equals("orderId"))
{
var orderId = Intent.Extras.GetString("orderId");
if (!string.IsNullOrEmpty(orderId))
{
if (ViewModel != null)
{
ViewModel.InitializeOrderAsync(int.Parse(orderId));
}
}
}
}
}
}
}