Android Question Terminating WebSocket PushService Properly

Discussion in 'Android Questions' started by iCAB, Jul 5, 2015.

  1. iCAB

    iCAB Active Member Licensed User

    I am facing some difficulties after adding Websocket Push Services code to my application. I particular
    I started getting "Unfortunately ProgramName has stopped" after terminating the app.
    The issue is due to some uninitialized variables that are being access by the Service ( please note that there is no issue while the application is running as all these variables are initialized proper during run time ).
    I am not sure what I am doing wrong in here, but here is what I have done so far to terminate the service when the application is terminated

    Code:
    #Region Service Attributes#StartAtBoot: false#StartCommandReturnValue: android.app.Service.START_STICKY#End Region
    Code:
    Sub Activity_DestroyTry
    StopService(WSPushService)Log( "destroyed" )
    Catch
    Log(LastException)
    EndTry
    End Sub
    I have also commented out: StartServiceAt in Service_Start
     
  2. Erel

    Erel Administrator Staff Member Licensed User

    Please use [code]code here...[/code] tags when posting code.

    Don't you want to receive push messages when your app is in the background?
     
  3. iCAB

    iCAB Active Member Licensed User

    The perfect scenario will be to receive push notifications when the app is in the background, but not after it is terminated by the user.
    Once the user closes the app, I don't want to receive the messages in this particular app.
     
  4. Erel

    Erel Administrator Staff Member Licensed User

    I think that it is better to use a service to manage the push messages. It will be simpler.

    Make sure that the service is not a sticky service, it doesn't start at boot and remove the StartServiceAt calls.

    You should also stop the timers when the service is destroyed.
     
  5. iCAB

    iCAB Active Member Licensed User

    Stopping the timer did the job.
    Thank you
     
Loading...