Android Question Service gets paused when app is updated

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?
 

Sandman

Well-Known Member
Licensed User
Apparently you can use a Broadcastreceiver to listen for the MY_PACKAGE_REPLACED action.
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:

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:
B4X:
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:

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?
 

Erel

Administrator
Staff 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?
Yes.

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?
The service will start automatically after the update. Similar to how it happens with #StartAtBoot feature.
 
Top