Android/Google Play - Can an App Update While it Is Running

前端 未结 1 943
予麋鹿
予麋鹿 2020-12-17 02:18

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

相关标签:
1条回答
  • 2020-12-17 02:52

    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.

    0 讨论(0)
提交回复
热议问题