Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.6k views
in Technique[技术] by (71.8m points)

android - Auto-restart app after market update

Anytime I publish a new version of my app in the Market, if the user had enabled the "auto update" option, the app will be updated automatically.

The app contains a service that runs constantly. But when the automatic update happens, the old running app is killed, but the new one is not started. Since the update happens mostly transparently to the user, it makes sense that the app's service should be started again automatically after the update so that there is almost no interruption of the service.

It's a bit difficult to test this with a real update from the market, so I'm using the following two adb commands to simulate this update process. Install of the 1st version:

adb install oldversion.apk

Automatic update:

adb install -r newversion.apk

After I run the second command, the app gets successfully updated, but it has been stopped and not restarted.

How can we make the new version's service start automatically?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

If your app is running on API 12 or higher, I would recommend registering a BroadcastReceiver listening to android.intent.action.MY_PACKAGE_REPLACED.

This Intent is only triggered if YOUR application got an update.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...