8

I am building an app that is designed to run continuously. Furthermore, the user is locked into the app (via the pinning feature) when it is being used. When the app has not detected user interaction for a while, it unpins itself, calls the Android dream service, and displays a screensaver of sorts. When the user taps the device, it 'wakes up', goes to the main screen, and repins itself.

I need my app to auto-update. However, given the circumstances, I have had difficulty in doing so. It simply does not seem to update, or according to one of my colleagues, updated but closed the app.

Is there a way for the app to detect, download, and install an update while running, and then, if necessary, relaunch itself? What would be the best approach?

Thanks much.

1
  • By update, you mean the content? or something else? If by content you can use Firebase Remote config
    – MatejMecka
    Commented Jul 5, 2016 at 14:51

1 Answer 1

12

Is there a way for the app to detect, download, and install an update while running

This is handled for you by google play store. An app is killed when it is going to be upgraded to a new version so the installation of the new version is smooth and data is not corrupted.

if necessary, relaunch itself?

If you want to keep running (or rather, restart the app) after an upgrade, yes you have to do some additional stuff.

A way that I use is this:
Put in manifest:

<receiver android:name=".receivers.AppUpgraded">
    <intent-filter>
        <action android:name="android.intent.action.MY_PACKAGE_REPLACED" />
    </intent-filter>
</receiver>

public class AppUpgraded extends BroadcastReceiver {

    @Override
    public void onReceive(final Context context, Intent intent) {
        // your app was just upgraded, restart stuff etc.
    }
}

Note there is also a action.PACKAGE_REPLACED which will trigger for ANY app that is upgraded. You're likely only interested in the upgrade of your own app, so use action.MY_PACKAGE_REPLACED.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.