How do I programmatically "restart" an Android app in.Net maui?
How do I programmatically "restart" an Android app in.Net maui?
I have been trying to restart the application when the system reboot in .net maui app
AndroidManifest.xml
BootBroadcastReceiver.cs
using global::Android.App;
using global::Android.Content;
[BroadcastReceiver(Enabled = true, DirectBootAware = true,Exported = true)]
[IntentFilter(new[] { Intent.ActionBootCompleted })]
public class BootBroadcastReceiver : BroadcastReceiver
{
public override void OnReceive(Context context, Intent intent)
{
Intent i = new Intent(context, typeof(MainActivity));
i.AddFlags(ActivityFlags.NewTask);
context.StartActivity(i);
}
}
[Activity(Theme = "@style/Maui.SplashTheme", MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation | ConfigChanges.UiMode | ConfigChanges.ScreenLayout | ConfigChanges.SmallestScreenSize | ConfigChanges.Density)]
public class MainActivity : MauiAppCompatActivity
{
BootBroadcastReceiver receiver;
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
receiver = new BootBroadcastReceiver();
}
}
I already tried all answers related to this in stackoverflow it is not working.
Environment: visual studio 2022 .NET MAUI version: MAUI 7.0