Android Question Service gets paused when app is updated

Discussion in 'Android Questions' started by Inman, Nov 2, 2018.

  1. Inman

    Inman Well-Known Member Licensed User

    My app has a service which has StartAtBoot=True. It used to be a sticky service, but since the app now targets API Level 26, it uses Service.AutomaticForegroundMode = Service.AUTOMATIC_FOREGROUND_ALWAYS instead.

    The service has a persistent notification icon. The problem is whenever a user updates the app from Play Store, this service gets stopped and notification disappears. I always thought it came back but today a user reported it doesn't and that's when I noticed as well.

    Is there something I should do to the service to make sure it gets started automatically after every Play Store update?
     
  2. Computersmith64

    Computersmith64 Well-Known Member Licensed User

  3. Sandman

    Sandman Well-Known Member Licensed User

    I've been wondering how one of my installed games always managed to put up a notification every time it was updated. This must be it. And for those interested in seeing this themselves, go see my post about games here at the forum. The game is Heads Off. (You'll obviously have to wait until the developer puts out a new release though.)

    Edit: I took a peek in Heads Off, and I was wrong - that Broadcastreceiver isn't used at all...
     
    Last edited: Nov 4, 2018
  4. Inman

    Inman Well-Known Member Licensed User

  5. Erel

    Erel Administrator Staff Member Licensed User

    You just need to add this to the manifest editor:
    Code:
    AddReceiverText(YourService, <intent-filter>
    <action android:name=
    "android.intent.action.MY_PACKAGE_REPLACED" />
     </
    intent-filter>)
    Make sure not to use the starter service for this.
     
    Inman, Computersmith64 and Sandman like this.
  6. udg

    udg Expert Licensed User

    Hi @Erel ,sorry to post it here, but I feel it's strictly related to your post #5.

    Instructions for my lib AppUpdating (used to update current apk to a newer one) invite the programmer to add the following to his/her Manifest file:
    Code:
    AddReceiverText(eu.dgconsulting.appupdating.newinst2,
      <
    intent-filter>
      <action android:name=
    "android.intent.action.PACKAGE_REPLACED" />
        <data android:scheme=
    "package" />
      </
    intent-filter>)
    It works ok, but as a side effect each time any app is updated on the device we can read about it in the logs (so this should mean that my code is awaken then put again to sleep).

    Would the simple substitution of "android.intent.action.PACKAGE_REPLACED" with "action android:name="android.intent.action.MY_PACKAGE_REPLACED" limit the calls to my code to times where the specific app using it is to be updated?

    BTW, reading this seems the change to become a need from Oreo on.
     
    Last edited: Nov 4, 2018
  7. Erel

    Erel Administrator Staff Member Licensed User

    Yes, if you are interested in monitoring your app updates then you should listen to MY_PACKAGE_REPLACED

    android.intent.action.PACKAGE_REPLACED can only be monitored with a dynamic receiver.
     
    udg likes this.
  8. Inman

    Inman Well-Known Member Licensed User

    So is it a better idea to use android.intent.action.MY_PACKAGE_REPLACED instead of android.intent.action.PACKAGE_REPLACED if all I want to make sure is my service is not paused every time my app is updated?

    Also are you saying that I don't need to do anything in app (like monitoring for this broadcast receiver) and that I only need to add the code to manifest file and that is it?
     
  9. Erel

    Erel Administrator Staff Member Licensed User

    Yes.

    The service will start automatically after the update. Similar to how it happens with #StartAtBoot feature.
     
    Inman likes this.
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice