0

使用 Xam.Plugins.Notifier 进行本地通知我可以在 Android 中显示通知。但是,当我点击通知时,它会重新加载应用程序。类似于远程通知的方式。

我在 MainActivitiy.cs 中处理 OnNewIntent() 但它从不触发。

如何点击 Xam.Plugins.Notifier 发出的本地通知,以便 OnNewIntent() 触发并且我可以显示 Shell 项目?

protected async override void OnNewIntent(Intent intent)
{
    base.OnNewIntent(intent);
    var title = intent.GetStringExtra("title");
    if (title != null)
    {
        await Shell.Current.GoToAsync("Tools/Sales");
    }
}

我有一个启动应用程序的 SplashScreen Activity:

如何将启动活动的 Intent 从 Splash 传递给 MainActitity

[Activity(Theme = "@style/MyTheme.Splash", MainLauncher = true, NoHistory = true, LaunchMode = Android.Content.PM.LaunchMode.SingleTop)]
public class SplashActivity : AppCompatActivity
{


    public override void OnCreate(Bundle savedInstanceState, PersistableBundle persistentState)
    {
        base.OnCreate(savedInstanceState, persistentState);
    }

    // Launches the startup task
    protected override void OnResume()
    {
        base.OnResume();
        StartActivity(new Intent(Application.Context, typeof(MainActivity)));
    }

    public override void OnBackPressed() { }


}
4

1 回答 1

0

MainActivty类上,将其设置为LaunchModeSingleTop以便操作系统将重用该活动,如果它已经全部运行,而不是开始一个新活动:

[Activity(Label = "Your Xamarin Forms App", MainLauncher = true, Icon = "@mipmap/icon", LaunchMode = Android.Content.PM.LaunchMode.SingleTop)]

注意MainActvity:通知意图有两个入口点

一个。如果活动已经在运行,OnNewIntent将按照您在通知中设置的意图进行调用。

湾。如果您的应用未运行,MainActvity将作为正常启动创建,但将包含来自通知的意图,因此请检查 OnCreate 中的意图。

于 2019-07-17T15:25:22.957 回答