Android Question Start in Foreground or Background Depending on Launch Method

Startup

Active Member
Licensed User
Longtime User
I would like my APP to start and stay in background (not visible) if started by user turning device on (using a service module with StartAtBoot set to True) , but start in foreground (visible) if started by user pressing launcher icon. Is there a way to do this?
 

JohnC

Expert
Licensed User
Longtime User
What Erel is trying to say is that if you have STARTATBOOT=true, then *just* that service will run when the user's device boot's up. And the main activity will only display/run when the user presses the launcher icon. It's up to your code how to handle these different methods.
 
Upvote 0

Startup

Active Member
Licensed User
Longtime User
Thanks JohnCody! That explains it and is just what I needed to understand to code my APP to do what I want it to do.
 
Upvote 0

Startup

Active Member
Licensed User
Longtime User
What Erel is trying to say is that if you have STARTATBOOT=true, then *just* that service will run when the user's device boot's up. And the main activity will only display/run when the user presses the launcher icon. It's up to your code how to handle these different methods.

I see the Starter service also runs when the device boots up with the other service set to StartAtBoot. How do I know? By putting a StartActivity(main) line in the starter service which gets the main activity to display. (Without the other service set to StartAtBoot or without the StartActivity(main) line in the Starter service the main Activity does not display). Would appreciate knowing if you agree with my finding here? Thanks!
 
Upvote 0

JohnC

Expert
Licensed User
Longtime User
As Erel stated (in the post when he added the starter service feature), that is a special service that is guaranteed to run before anything else so you can place certain code that needs to run first before anything else.

You don't have to use the starter service at all.
 
Upvote 0

JohnC

Expert
Licensed User
Longtime User
..so if you set your "startatboot" service to "False", then the starter service wont run until the user starts the app with it's icon.

In other words, the Starter Service wont run until your app get's loaded into memory by one of these two things happening:

1) Another service is set to "startatboot" and the device boots up, or
2) When the user launches the app from it's icon
3) .. or when the app is launched by setting up a scheduled task for it (almost forgot about this one)
 
Upvote 0
Top