M mw71 Well-Known Member Licensed User Longtime User Nov 3, 2020 #1 Hi, 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: Copy 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: Copy StartActivity(Main) 'for test CallSubDelayed(Main,"Reboot")
Hi, 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: Copy 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: Copy StartActivity(Main) 'for test CallSubDelayed(Main,"Reboot")
Erel B4X founder Staff member Licensed User Longtime User Nov 4, 2020 #2 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. Upvote 0
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.