Android Question The Servic Module not be closed

CyclopDroid

Well-Known Member
Licensed User
Longtime User
Hi,
When i close the Service, it continue to start at volume key press.:confused:
In my app, when i close the Service I write:

Main
B4X:
Sub Activity_Create(FirstTime As Boolean)
If DestroyApp=True Then
    CancelScheduledService(srvPickUp)
    StopService(srvPickUp)
    Activity.CloseMenu
    Activity.RemoveAllViews
    Activity.Finish
    ExitApplication
  Else


Activity.Finish
End If
End Sub

the DestroyApp is a global boolean declared into Main and assigned to value True into Service.

The App are closed but, when i press a volume up or down... the Service create and Start Again:eek:
Why?:confused:

This is the Log when Start after close the service and press a volume key, into Service:


B4X:
Sub Service_Start (StartingIntent As Intent)
Dim curVol As Int
If StartingIntent.HasExtra("android.media.EXTRA_VOLUME_STREAM_VALUE") Then
           curVol = StartingIntent.GetExtra("android.media.EXTRA_VOLUME_STREAM_VALUE")
      Log("Service_Start: Volume")
...
...
...

This is a LOG


B4X:
** Service (srvpickup) Start **
** Activity (menu) Create, isFirst = true **
** Activity (menu) Resume **
** Service (srvpickup) Start **
Service_Start: Volume
** Service (srvpickup) Start **
** Service (srvpickup) Start **
** Service (srvpickup) Start **
** Activity (menu) Pause, UserClosed = true **
** Service (srvpickup) Start **
** Service (srvpickup) Start **
** Service (srvpickup) Start **
** Service (srvpickup) Start **
** Service (srvpickup) Start **
** Service (srvpickup) Start **
** Service (srvpickup) Start **
** Service (srvpickup) Start **
** Service (srvpickup) Start **
** Service (srvpickup) Start **
** Activity (main) Create, isFirst = true **
Main: End

The Debug it's closed and the App finish but... when I click a volume key... it's Start again

B4X:
** Service (srvpickup) Create **
** Service (srvpickup) Start **
Service_Start: Volume
** Service (srvpickup) Start **
Service_Start: Volume
** Service (srvpickup) Start **Service_Start: Volume
** Service (srvpickup) Start **
** Service (srvpickup) Start **
** Service (srvpickup) Start **
** Service (srvpickup) Start **
** Service (srvpickup) Start **
** Service (srvpickup) Start **
** Service (srvpickup) Start **
** Service (srvpickup) Start **
 
Last edited:

CyclopDroid

Well-Known Member
Licensed User
Longtime User
Hi Erel,

In this Service, when i remove the Widget to the screen, I view this LOG, eand the App, enter into Main Activity, when it stoped the service and exit to the app.

B4X:
    If StartingIntent.Action = "android.appwidget.action.APPWIDGET_DELETED" Then
        Log("Service_Start:action.APPWIDGET_DELETED")
        Return
    End If

If rv.HandleWidgetEvents(StartingIntent)=False Then
    If StartingIntent.Action="android.appwidget.action.APPWIDGET_UPDATE_OPTIONS" Then
        StartActivity(Menu)
    End If
Else
    Log("Service_Start:HandleWidgetEvents")
    Return
End If
rv_RequestUpdate
'Fine
End Sub

...Into Main Activity, I've this code at Create :

B4X:
If DestroyApp=True Then
    srvPickUp.WidTimer.Enabled=False
    MyLog("Main: Fine")
    srvPickUp.WidTimer.Enabled=False
    StopService(srvPickUp)
    CancelScheduledService(srvPickUp)
   
    Activity.CloseMenu
    Activity.RemoveAllViews
    Activity.Finish
    ExitApplication
End If


The DestroyApp=True is into Service Destroy:


B4X:
Sub rv_Disabled
If Main.FirstClick=True Then
    ToastMessageShow("The Widget is Closed",True)
    Main.PrimoRing=0
    Main.FirstClick=False
    Main.VolumeOnOff=True
    Main.tmpVolumeOnOff=True
    tmrSquilli.Enabled = False

    Main.DestroyApp=True
    StartActivity(Main)
  End If
End Sub

...but I have tried to put after the logs , into the code posted above, the Stop Service and it close... but, at the pressure of the volume keys , always starts again. :(


B4X:
If StartingIntent.Action = "android.appwidget.action.APPWIDGET_DELETED" Then
        Log("Service_Start:action.APPWIDGET_DELETED")
        WidTimer.Enabled=False
        StopService(Me)
        CancelScheduledService(Me)
        ExitApplication
End If
 
Upvote 0

CyclopDroid

Well-Known Member
Licensed User
Longtime User
This is the code when I intercept the Volume key press but, if I remove it, the Service start again same.


B4X:
Sub Service_Start (StartingIntent As Intent

If Main.DestroyApp=False Then
    StartServiceAt("",DateTime.Now + 0.1 * DateTime.TicksPerMinute,False)
    WidTimer.Enabled=True
Else   
    Log("stopped")
    StopService(Me)
    CancelScheduledService(Me)
   
    WidTimer.Enabled=False
    ExitApplication
End If

'Intercept the volume key
Dim curVol As Int

If StartingIntent.HasExtra("android.media.EXTRA_VOLUME_STREAM_VALUE")  Then
       curVol = StartingIntent.GetExtra("android.media.EXTRA_VOLUME_STREAM_VALUE")
      Log("Servoice_Start: Volume Intercept")
....
....
....
 
Upvote 0

CyclopDroid

Well-Known Member
Licensed User
Longtime User
This is my Manifest;


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" android:targetSdkVersion="14"/>
<supports-screens android:largeScreens="true"
    android:normalScreens="true"
    android:smallScreens="true"
    android:anyDensity="true"/>)
SetApplicationAttribute(android:icon, "@drawable/icon")
SetApplicationAttribute(android:label, "$LABEL$")

SetActivityAttribute(Main, "android:excludeFromRecents", "true")
SetActivityAttribute(Menu, "android:excludeFromRecents", "true")

AddReceiverText(srvPickUp, <intent-filter>
    <action android:name="android.intent.action.MEDIA_BUTTON" />
    </intent-filter>)
  
AddReceiverText(srvPickUp, <intent-filter>
    <action android:name="android.media.VOLUME_CHANGED_ACTION" />
    </intent-filter>)

AddPermission("android.permission.CALL_PHONE")
AddPermission(android.permission.MODIFY_AUDIO_SETTINGS)
'End of default text.
 
Upvote 0

CyclopDroid

Well-Known Member
Licensed User
Longtime User
Thanks Erel. In effect, if I remove the:


B4X:
AddReceiverText(srvPickUp, <intent-filter>
    <action android:name="android.intent.action.MEDIA_BUTTON" />
    </intent-filter>)
 
AddReceiverText(srvPickUp, <intent-filter>
    <action android:name="android.media.VOLUME_CHANGED_ACTION" />
    </intent-filter>)

from the Manifest, the App and the Service terminate!

...but now, i don't intercept the Volume key that I needed to change the image of widgets when these keys were pressed. :(
 
Upvote 0

CyclopDroid

Well-Known Member
Licensed User
Longtime User
Ok, it's true. Thaks you and Udg for support.;)
 
Upvote 0
Top