my App run 24/7. All 30' start's a "Watchdog Service".
In this Service i check if the App Run more then 24h. If true i will Restart the App.
The Check works, the Reboot not.
my attempt
the restart in the Main (Activity)
B4X:
Sub Reboot
Dim Writer As TextWriter
File.Delete(File.DirInternal,"RebootTime.txt")
Writer.Initialize(File.OpenOutput(File.DirInternal, "RebootTime.txt", False))
Writer.WriteLine(DateTime.Now)
Writer.Close
Activity.Finish
StartActivity(Me)
End Sub
and the Call from the Service
B4X:
StartActivity(Main) 'for test
CallSubDelayed(Main,"Reboot")
There is almost never a good reason to use TextWriter. File.WriteString is better.
Recreating the activity will not help with running an app for a long time.
You need to have a second app with a foreground service that sends an intent to the main app. The main app should close itself (ExitApplication). A few seconds later the watchdog app should send another intent that will start the main app.