I know is later ... but still.... looking to the answer to your problem(cause i am still b4a beginner,java 0 =i'll never learn java) .. i found the answer ,i mean Erel did in da past .thanks Erel for
https://www.b4x.com/android/forum/t...-long-running-background-tasks.27065/#content still works!
is about #StartCommandReturnValue: android.app.Service.START_STICKY
here is a small example will set allways vibrations instread sounds on your andoid phone.
(on my phone with android 6.0.1 if i set vibrations instread sounds after any call the phone app will set sounds overriding my settings so treat this experiment like a fix for my phone with android version)
i compiling this using android targetSdkVersion="19" on an android 6.0.1 and works !
the libraries are core and phone ...see on the right side-bottom da book then you may activate phone library(for begginers ninja
)
in the main
#Region Project Attributes
#ApplicationLabel: CUSTA-mizable
#VersionCode: 1
#VersionName: 0
'SupportedOrientations possible values: unspecified, landscape or portrait.
#SupportedOrientations: unspecified
#CanInstallToExternalStorage: True
#End Region
#Region Activity Attributes
#FullScreen: False
#IncludeTitle: False
#End Region
Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
End Sub
Sub Globals
'These global variables will be redeclared each time the activity is created.
'These variables can only be accessed from this module.
Activity.Finish
End Sub
Sub Activity_Create(FirstTime As Boolean)
'Do not forget to load the layout file created with the visual designer. For example:
'Activity.LoadLayout("Layout1")
End Sub
Sub Activity_Resume
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub
in the service starter i use
#Region Service Attributes
#StartAtBoot: True
#ExcludeFromLibrary: True
#StartCommandReturnValue: android.app.Service.START_STICKY
#End Region
Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
Dim p As Phone
Dim vl As Int
Dim timer1 As Timer
End Sub
Sub Service_Create
'This is the program entry point.
'This is a good place to load resources that are not specific to a single activity.
End Sub
Sub Service_Start (StartingIntent As Intent)
timer1.Initialize("Timer1", 500)
timer1.Enabled = True
End Sub
'Return true to allow the OS default exceptions handler to handle the uncaught exception.
Sub Application_Error (Error As Exception, StackTrace As String) As Boolean
Return True
End Sub
Sub Service_Destroy
End Sub
Sub Timer1_Tick
'If p.GetVolume(p.VOLUME_RING)>0 Then
' p.SetVolume(p.VOLUME_RING, 0, True)
' pp=False
'End If
'delay
'
vl = p.GetVolume(p.VOLUME_RING)
If vl>0 Then
'Log("da")
p.SetVolume(p.VOLUME_RING, 0, True)
Else
'Log("nu")
End If
'Log(vl)
End Sub
how this work ? if pushing volume in android 6.0.1 will popup da bar then touching quick da arrow on da right of percents of voume then will popup a new small window ,then if you try to set ringtone to other values >0 the service will put it to 0 that's meaning "to vibrate".if you try to kill my app from recent apps this will kill activity and the service will live in backgroung.the unique way to kill it is settings / applications/application manager/the name you choose to try this in my case is CUSTA-misable\and Force stop and when popup confirmation force stop again.
the seccond way is simple as uninstall from the same place.[/code]