Android Question StartAtBoot starter module attributes

Startup

Active Member
Licensed User
Longtime User
I want to have my APP StartAtBoot. Erel says don't set StartAtBoot to True for the Starter module (which I use to create and initialize process variables). I am puzzled why that option is possible in the starter module template if it should not be used? (not meaning to be a wise guy just trying to see if I understand correctly). Also I see NJDude's StartAtBoot sample program has its StartAtBoot attribute in its Starter module set to True. I would like to use NJDude's sample APP to start my APP so I am thinking ... should I create a separate service module (say StartupService?) to incorporate the code in the starter module of NJDude's s sample program to comply with what Erel says to do? And if so should I have the line in NJDude's sample program ...
i.SetComponent("njdude.startatboot.sample/.main") ...
have .main replaced by .starter to have the program once started up then go immediately to the starter service ?​
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
I am puzzled why that option is possible in the starter module template if it should not be used?
The IDE doesn't treat the starter service differently so it shows the same options.

I'm not familiar with the sample program that you are referring to. You don't need any sample to use StartAtBoot. Just create another service and add #StartAtBoot: True.
 
Upvote 0

Startup

Active Member
Licensed User
Longtime User
The IDE doesn't treat the starter service differently so it shows the same options.

I'm not familiar with the sample program that you are referring to. You don't need any sample to use StartAtBoot. Just create another service and add #StartAtBoot: True.
Thanks Erel! StartAtBoot does not start the APP if the APP has been previously closed as I understand it and in my experience. However, NJDude's sample (see this link) does. However, the sample program starts the program in the main module not the starter module so although the APP starts at boot when previously closed I don't get the variables set and initialized in the starter module when I use NJDude's sample. I suppose I can set the variables in the Main module but then I lose the benefit of using the starter module as the entry point. I want to start the APP at boot even if previously closed and be able to use the starter module as the entry point. Any suggestions how to do this much appreciated! (I tried changing NJDude's sample program replacing .main with .starter but that didn't work).
 
Upvote 0

Startup

Active Member
Licensed User
Longtime User
There is nothing special in that sample. It just sets StartAtBoot to true.

As I previously wrote, you shouldn't start the starter service directly.

Thanks Erel. You say there is nothing special in that sample (here is a link to it .. and I've repeated the code from the sample below) however I find that it starts the APP even when previously closed (which I want to do) while if I just have StartAtBoot to True (without this code) it does not start the APP (when previously closed). Is there something I'm missing here? Thanks!

Note: Below is the code in the sample that I believe makes the APP start even if previously closed. Correct?

Sub Service_Create
Dim i As Intent

i.Initialize("", "")
i.SetComponent("b4a.CheckInRedo/.main") '<-- Replace this with the name of your package

StartActivity(i)

StopService("")
End Sub
 
Upvote 0

Startup

Active Member
Licensed User
Longtime User
Please use [code]code here...[/code] tags when posting code.

I don't see anything special in that code that will cause the standard OS enforced behavior to change. However if you want you can add this intent to your code. It is equivalent to calling StartActivity(Main).

Thank you that's much better. I replaced that sample code with StartActivity(Main) and it works fine and has the added advantage of being simpler and something I actually understand :) .
One more question: You said in another post (link here) "Make sure not to kill the app as it will prevent it from starting (don't swipe it from the recent apps list)." But my APP does StartAtBoot when previously closed (which I want it to do). So I'm not sure what you mean unless there are different devices or android versions where what works for me here won't work? Thanks!
 
Upvote 0
Top