更新时间:2023-01-30 08:36:04
您需要添加 ="noreferrer"> ActivityFlags.NewTask
标记为意图,因为您要在活动上下文之外启动活动.
You need to add the ActivityFlags.NewTask
flag to the intent because you are launching an activity outside of an activity context.
崩溃是因为引导接收器生成了 Android.Util.AndroidRuntimeException
.
The crash is because a Android.Util.AndroidRuntimeException
is generated by the boot receiver.
解决方案:
[BroadcastReceiver]
[IntentFilter(new[] { Intent.ActionBootCompleted }, Priority = (int)IntentFilterPriority.LowPriority)]
public class BootReceiver : BroadcastReceiver
{
public override void OnReceive(Context context, Intent intent)
{
Intent serviceStart = new Intent(context, typeof(MainActivity));
serviceStart.AddFlags (ActivityFlags.NewTask);
context.StartActivity(serviceStart);
}
}