使用Xam.Plugins.Notifier进行本地通知,我可以在Android中显示一个通知。但是,当我点击通知时,它会重新加载应用程序。类似于远程通知的方式。
我在MainActivitiy.cs中处理MainActivitiy.cs(),但它从不触发。
如何点击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活动:
如何将启动活动的意图从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() { }
}发布于 2019-07-17 15:25:22
在MainActivty类上,将其LaunchMode设置为SingleTop,以便如果活动已经运行,操作系统将重用该活动,而不是启动一个新的活动:
[Activity(Label = "Your Xamarin Forms App", MainLauncher = true, Icon = "@mipmap/icon", LaunchMode = Android.Content.PM.LaunchMode.SingleTop)]注意事项:对于通知意图,MainActvity有两个入口点
如果该活动已在运行,则将调用OnNewIntent,其目的是在通知上设置。
如果您的应用程序没有运行,MainActvity将作为一个正常的启动程序创建,但将包含来自通知的意图,因此请检查OnCreate中的意图。
https://stackoverflow.com/questions/57079107
复制相似问题