Autostart apps

mjtaryan

Active Member
Licensed User
Longtime User
I have a project I'm beginning to lay out that has two linked parts. The first part is quite short. It is to run in the background and awakens whenever the screen is unlocked. It then checks whether or not the current unlocking of the screen/device is the first of the the current day. If it is not, this "widget" or "service" goes back to sleep. If it is the first unlock of the day, it displays a message box with a reminder and two buttons, "Continue" and "Cancel." The Cancel button puts the widget/service back to sleep. The Continue button calls the main program and then goes back to sleep.

My problem is that I don't know how to do this running in the background and awakening in Android (and using B4a). Can anyone help? Thanks.
 
Last edited:

Erel

B4X founder
Staff member
Licensed User
Longtime User
A service module can run in the background. You can also make it start at boot by checking this option under Project - Service properties.

PhoneEvents allows you to listen for the screen unlocked event (UserPresent event).

However in order for Android not to kill your service you will need to call Service.StartForeground when your service starts.
 
Upvote 0

mjtaryan

Active Member
Licensed User
Longtime User
Thanks Erel. Is there documentation for the things you mention so I can read the details (link would be helpful)?
 
Upvote 0
Top