Android Question Restart app through starter service?

wimpie3

Well-Known Member
Licensed User
Longtime User
When android removes my activity from the memory (due to people switching to other apps probably) I want to restart the app completely when they come back to the app. Is this possible with the starter service or is there another solution?
 

KMatle

Expert
Licensed User
Longtime User
See this thread: https://www.b4x.com/android/forum/t...-service-long-running-background-tasks.27065/

My favourites:

- start the service in foreground (a notification will be set to inform the user that there's an app running in the "background). This is very reliable. The Service will be restarted.

B4X:
Sub Service_Create
    sNotif.Initialize
    sNotif.Icon = "icon"
    sNotif.Vibrate=False
    sNotif.SetInfo2("GPSPinger","Service Running","FromNotification",Main) 'If the notification is clicked, the main activity will be started
    sNotif.Sound = False
    sNotif.Notify(1)
    Service.StartForeground(1,sNotif)
End Sub

Even better:

- if your app can be triggered (e.g. new SMS or Firebase Message, etc.) use an intent. The app (the service) will be started automatically. Search for "intercept" and/or "intents"
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
When android removes my activity from the memory (due to people switching to other apps probably) I want to restart the app completely when they come back to the app.
You can call ExitApplication to kill the process, however the OS will treat your app as if it has crashed and it may try to restart it immediately.

What do you mean with restart the app completely? The UI will be completely recreated after the activity has been destroyed.
 
Upvote 0
Top