Android Question How to check if a service exist?

stefanoa

Active Member
Licensed User
Longtime User
I create a service called "Player"
B4X:
    Player.filesMap = filesMap
    Player.currentSongIDx=IDx
    StartService(Player)
afterwards, from other activities, i need to get some information from MediaBrowser (if is playing, lenght, etc.) that is inside the service, avoiding "null object errors"
i tried:
B4X:
If  Player <> Null Then
        If Player.MB.MediaIsPlaying....
but doesn't work
It's possible?
thanks
 
Last edited:

stefanoa

Active Member
Licensed User
Longtime User
I assume that MB is a process global variable. You don't need to check whether Player is Null or is sleeping.

However as a general rule, all public process global objects should be in the starter service and initialized in Service_Create. This way they will always be initialized.
I did not know this service.
I solved with Starter service and global declaration
Thanks!
 
Upvote 0
Top