Android Question how to stop a service using intent?

Mrjoey

Active Member
Licensed User
Longtime User
hello , im using a library for lockscreen :http://www.b4x.com/android/forum/th...n-lockscreen-with-just-5-lines-of-code.43327/
wish has a service called "LockScreenService" , here is the manifest:

B4X:
AddApplicationText(
    <service android:name="com.datasteam.b4a.system.lockscreen.LockScreenService">
        <intent-filter >
            <action android:name="com.datasteam.b4a.system.lockscreen.LockScreenService" />
        </intent-filter >
    </service>)
the problem is the service stays running even if i exit my app , and it has no function to stop its own service therefore i would like to stop it using intent , i saw a example by Mr Erel solving someone problem using this code:
B4X:
SetReceiverAttribute(HttpUtilsService, android:exported, "true")

B4X:
Dim p As Phone
Dim i As Intent
i.Initialize("", "")
i.SetComponent("anywheresoftware.b4a.samples.flickr/.httputilsservice$httputilsservice_BR")
p.SendBroadcastIntent(i)

i tried it by changing to :
B4X:
SetReceiverAttribute(LockScreenService, android:exported, "true")

and
B4X:
Dim p As Phone
Dim i As Intent
i.Initialize("", "")
i.SetComponent("com.datasteam.b4a.system.lockscreen/.LockScreenService$LockScreenService_BR")
p.SendBroadcastIntent(i)

but i got an error when compiling and says :
could not find module :LockScreenService_BR.

how to solve it , thank u.
 

Mrjoey

Active Member
Licensed User
Longtime User
Add a new service to your project and let this service handle the intent (and then call StopService(LockScreenService)).
do u mean creating a new service called"LockScreenService" and then on "service_start(...) i put :
B4X:
Dim p As Phone
Dim i As Intent
i.Initialize("", "")
i.SetComponent("com.datasteam.b4a.system.lockscreen/.LockScreenService$LockScreenService_BR")
p.SendBroadcastIntent(i)
 
Upvote 0

Mrjoey

Active Member
Licensed User
Longtime User
No. How are you currently interacting with LockScreenService (inside your app)?
I meant that you create a new service and let this service handle the intent and in Service_Start call StopService(LockScreenService).
the service is located inside the library , not in my app.
can u give me a small example please , thank u.
 
Upvote 0

Mrjoey

Active Member
Licensed User
Longtime User
Create a service in your app named MyService. Expose MyService with the SetReceiverAttribute code you posted. Now in MyService inside Service_Start call StopService(LockScreen).
Mr Erel , "LockScreen" does not exist , instead there is a service inside a library called "LockScreenService" i need to access it and stop it , how to do it ?
 
Upvote 0

Mrjoey

Active Member
Licensed User
Longtime User
Try to follow my suggestion which is to add a new service, call the new service and stop the other service from the new service.
failed ,
created a service called "test" , added this at the end of the manifest :
B4X:
SetReceiverAttribute(test, android:exported, "true")
called StartService(test) on the activity create , and then in the test service :
B4X:
Sub Service_Start (StartingIntent As Intent)
Dim p As Phone
StartingIntent.Initialize("", "")
StartingIntent.SetComponent("com.datasteam.b4a.system.lockscreen/.LockScreenService$LockScreenService_BR")
p.SendBroadcastIntent(StartingIntent)
StopService(StartingIntent)
End Sub
and the service still running..
 
Upvote 0

Mrjoey

Active Member
Licensed User
Longtime User
You should call something like StopService(LockScreenService).
B4X:
Parsing code.                           Error
Error parsing program.
Error description: Undeclared variable 'lockscreenservice' is used before it was assigned any value.
Occurred on line: 22
StopService(LockScreenService)
 
Upvote 0

Mrjoey

Active Member
Licensed User
Longtime User
You should call something like StopService(LockScreenService).
im very sorry mr Erel for bothering u in such annoying problem, although this problem has to be solved by the non responsive author of that library.
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Is the service you want to stop a service from your app or from another app?
 
Upvote 0
Top