Android Tutorial Service Modules

Discussion in 'Tutorials & Examples' started by Erel, Jan 27, 2011.

  1. BaGRoS

    BaGRoS Member Licensed User

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


    I added
    Code:
    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.
     
  2. Erel

    Erel Administrator Staff Member Licensed User

  3. BaGRoS

    BaGRoS Member Licensed User

    Thank you for your help. So I have to run the application, and just hide it.
     
  4. danijel

    danijel Member Licensed User

    Hi Erel,
    I used simple program to check a service by schimanski:
    http://www.basic4ppc.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 ?
     
  5. Erel

    Erel Administrator Staff Member Licensed 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.
     
  6. danijel

    danijel Member Licensed User

    Thx, where i can find those logs ? :)
     
  7. Erel

    Erel Administrator Staff Member Licensed User

  8. danijel

    danijel Member Licensed User

    Ok, but when I reset the phone, communication with B4a and log printing is lost. I thought there might actually log file somewhere. Error appears when the phone is restarted and when I start app manually, even though it has already launched by "#StartAtBoot: True"
     
  9. Erel

    Erel Administrator Staff Member Licensed User

    Start the logs again. The logs are written to a system cache so you will see the error even if it happened a few seconds (or more) ago.
     
  10. kiki78

    kiki78 Active Member Licensed 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
     
  11. Erel

    Erel Administrator Staff Member Licensed User

    Do all the activities know what to do with this event? What are you showing?
     
  12. hb_2013

    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.
     
  13. Erel

    Erel Administrator Staff Member Licensed User

    You should use CallSubDelayed.
     
  14. hb_2013

    hb_2013 New Member

    Thanks. Now it works.
     
  15. Turbo3

    Turbo3 Active Member Licensed 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: Dec 8, 2013
  16. Erel

    Erel Administrator Staff Member Licensed User

    Not at all. You should use AsyncStreams.
     
  17. mitsusdev

    mitsusdev Active Member Licensed 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 ?
     
  18. Erel

    Erel Administrator Staff Member Licensed User

    You will never have 2 services.
    Service_Create will be executed if the service was not running before. Service_Start will be raised each time the service is "started".

    You can use IsPaused to test whether the service is running.
     
  19. udg

    udg Expert Licensed 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
     
  20. Erel

    Erel Administrator Staff Member Licensed User

    Note that it was better to start a new thread for this question, it is not really related to this tutorial.

    You can use the activity name instead of the activity reference:
    Code:
    Notification.SetInfo("Title""Body""Main")
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice