How to kill a service proberly

mrossen

Active Member
Licensed User
Longtime User
Hi.

I have an app with a service running.

Now I have made a Stop service button that runs a

B4X:
Stopservice(bluetoothservice)

This looks to work fine because I got :

B4X:
Sub Service_Destroy

   ToastMessageShow("Close Service", False)
   ExitApplication
   
End Sub

the message "Close service" and the apps exits.

But When I turn on my bluetooth device again the service pops up again?

I have the service running in foreground. Do I need to stop this or will it stops aut. when the service closes?

B4X:
 Service.StartForeground(1, Notification1)

Or do I need to run this

B4X:
Service.StopForeground("")

Mogens
 

mrossen

Active Member
Licensed User
Longtime User
Hi Erel,

Thanks for your reply,

I have tried to run without ExitApplication, but the result is the same.

How long time is the normal for the process to kill? I have waited more than 5 min.

Is there a way to see is the process still running?

Mogens
 
Upvote 0

mrossen

Active Member
Licensed User
Longtime User
The problem is:

When I kill the app with all the described code lines the app close as it has to.

But when the bluetooth in the phone come in range to something it knows, the app running again. I can simply not kill it.

Mogens
 
Upvote 0

mrossen

Active Member
Licensed User
Longtime User
I am using serial1.StopListening.

B4X:
Sub Service_Destroy

   Serial1.Disconnect
   Serial1.StopListening
   Service.StopForeground(1)
   ToastMessageShow("Close Service", False)
   'ExitApplication
   
End Sub

The only way I can prevent the app to popup when I turn on my bluetooth device, is to uninstall it.

It is my bluetooth device there are master and are look for known phones all the time. When it find a known phone it will try to connect.

Can this be the problem?

Mogens
 
Upvote 0

mrossen

Active Member
Licensed User
Longtime User
This is the manifest edit from b4a

B4X:
'This code will be applied to the manifest file during compilation.
'You do not need to modify it in most cases.
'See this link for for more information: http://www.b4x.com/forum/showthread.php?p=78136
AddManifestText(
<uses-sdk android:minSdkVersion="4" />
<supports-screens android:largeScreens="true" 
    android:normalScreens="true" 
    android:smallScreens="true" 
    android:anyDensity="true"/>)
SetApplicationAttribute(android:icon, "@drawable/icon")
SetApplicationAttribute(android:label, "$LABEL$")
AddApplicationText(<activity android:name="anywheresoftware.b4a.objects.preferenceactivity"/>)
AddReceiverText(BluetoothService, <intent-filter>
 <action android:name="android.bluetooth.device.action.ACL_CONNECTED"/>
 </intent-filter>)
 AddReceiverText(BluetoothService, <intent-filter>
 <action android:name="android.bluetooth.device.action.ACL_DISCONNECTED"/>
 </intent-filter>)
 AddPermission(android.permission.BLUETOOTH)
'End of default text.
 
Upvote 0
Top