How do I programmatically "restart" an Android app in.Net maui?

San Sheva Santhanaraj 0 Reputation points
2023-09-25T15:57:33.59+00:00

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

Developer technologies | .NET | .NET MAUI
{count} votes

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.