Hello,
Firstly, please open your AndroidManifest.xml file and add following permissions in the <manifest>
.
<uses-permission android:name="android.permission.SCHEDULE_EXACT_ALARM" android:maxSdkVersion="32"/>
<uses-permission android:name="android.permission.USE_EXACT_ALARM" />
Then, you can use following code to restart your application.
#if ANDROID
var context = Platform.AppContext;
PackageManager packageManager = context.PackageManager;
Intent intent = packageManager.GetLaunchIntentForPackage(context.PackageName);
ComponentName componentName = intent.Component;
Intent mainIntent = Intent.MakeRestartActivityTask(componentName);
mainIntent.SetPackage(context.PackageName);
context.StartActivity(mainIntent);
Runtime.GetRuntime().Exit(0);
#endif
And donot forget to add following namespace.
#if ANDROID
using Android.App;
using Android.Content;
using Android.Content.PM;
using Java.Lang;
#endif
As note: Please do not test this code in the debug mode, you can install application in the debug mode. Then stop the debug in VS. You can find your application in the emulator or device, open it manually and test this application restart code.
Best Regards,
Leon Lu
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.