开发者

Restart Service for App on SD Card When SD Card Is Remounted

Due to overwhelming user complaints I have decided try allowing users of my Android application to move it to the SD card as per the official documentation. However, a core feature of my application requires a background service to be continuously running. When someone who has moved my app to their SD card mou开发者_如何学Gonts their SD card for whatever reason, my background service will be killed.

That's all okay by me, as long as I can restart the service at the first available opportunity. Unfortunately, despite the install-location guide claiming I can use the Broadcast Intent ACTION_EXTERNAL_APPLICATIONS_AVAILABLE to detect when the SD card is remounted locally, the documentation for that flag itself, this newsgroup discussion, and my own testing show that this broadcast is not delivered to the applications which become available. Only applications which have not been moved to the SD card get the Broadcast Intent.

Is there any way to restart my background service without waiting for the user to open my app after the SD card is remounted?


Not reliably. You could hook into permission-less broadcast Intents (e.g., ACTION_SCREEN_OFF) that should fire eventually and get control that way. As Ms. Hackborn indicates, the right answer is for ACTION_EXTERNAL_APPLICATIONS_AVAILABLE to be fixed. You might also see if some SD card-related broadcast happens to occur after external applications are available (e.g., ACTION_MEDIA_MOUNTED), though I would expect all of those to have passed before the external application is available.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜