Android Tutorial Service Modules

BaGRoS

Active Member
Licensed User
Longtime User
When you say "services not work" you mean that the services do not start after a boot?

Yes, do not start services after a boot, if the application is not started even once.


I also recommend you to remove the "android.intent.action.MAIN" action.

I added
B4X:
AddReplacement(<action android:name="android.intent.action.MAIN" />, )
AddReplacement(<category android:name="android.intent.category.LAUNCHER" />, )

but services not start after boot, if the application is not started even once.
 

BaGRoS

Active Member
Licensed User
Longtime User
Thank you for your help. So I have to run the application, and just hide it.
 

danijel

Active Member
Licensed User
Longtime User

Hi Erel,
I used simple program to check a service by schimanski:
http://www.b4x.com/android/forum/threads/service-modules.7542/#post-43012
... and works just fine.

But then I set #StartAtBoot: True
and then when I reset the phone and start the APP i get Error:
"Unfortunately Test has stopped."
Do you know what is problem ?
 

danijel

Active Member
Licensed User
Longtime User
You should check the logs while you reset your phone. There should be an error message.

My guess: the process starts from the service and you are accessing a variable that is only initialized when the main activity starts.

Thx, where i can find those logs ?
 

kiki78

Active Member
Licensed User
Longtime User
I embedded all necessary code to communicate with USB specific card in service.
Due to asynchronism, I need to call events from service to current activity of my application.
I never found "CurrentActivity" property anywhere.
For now I use CallSub on each potential activity, but it's not really elegant !
What is the best way to do that ?

Regards
 

hb_2013

New Member
Hi Erel.
Is there a way to load our activity and layout of it , with calling it from the service?(CallSub does not work at this case)
for example , I want to show a MessageBox when the phone was unlocked.
the MessageBox call is in activity , and the event recognition is in service module.
 

Turbo3

Active Member
Licensed User
Longtime User
Is it necessary to use DoEvents in a service routine? The service routine handles Bluetooth serial data (AStream_NewData).

While the code is consuming the incoming byte stream is it necessary to insert some DoEvents? It is a 38,400 baud rate link. Data from the link is loaded into global variables for use by the Activity code which displays it to the user. The service routine processes the bytes it gets and then exit until more bytes are received.

If so how frequently do they need to be execute relative to the baud rate?
 
Last edited:

mitsusdev

Member
Licensed User
Longtime User
if i set "StartAtBoot: True" and run "StartService" into first activity, when i reboot the phone and run the application.

have i 2 active services ?

can i check is service is already presence ?
 

udg

Expert
Licensed User
Longtime User
Hi,
I don't know if that's the intended way to use a service, but I'd like to develop a library made up of a single service which run all the day checking some web data every couple of hours.
Each time the service discovers new data it should be able to notify the OS which in turn (on user intervention) has to launch an appropriate app (the one linking in the above mentioned lib?) which has to take care of that new data.

Problem: if the service is in a lib, Notifications can't refer to Main but only to service itself.

So, am I expected to receive the OS notification in the Main part of the service lib and from there start the wanted activity?

Umberto
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…