Friday, September 2, 2011

[android-developers] app2sd restrictions - sharing a workaround to allow moving your app to SD card

Android recommends that certain apps should not be moved to SD card,
e.g. alarm clocks, etc.
See http://developer.android.com/guide/appendix/install-location.html

The reason for that is, among other things, that when the sd card is
unmounted, registrations with the alarm service are canceled, and the
app is no longer accessible. When the SD card is mounted again, there
is no way to launch the app to reregister those services.

So how do you get such apps to work on SD card anyways? I got my app
(Gentle Alarm) to work on SD card with a little trick that I share
here.

Notice: Of course the app won't work if the SD card is unmounted. So
this is NOT a solution for apps that need to remain accessible all the
time such as live wallpapers.

1) Create an additional small app that remains in memory. If you have
a widget for your app, you can use that as widget must stay in
internal memory anyways. I will call this app B.

2) If the SD card is unmounted, your app A is no longer accessible.
App B can notify the user accordingly if desired.

3) If the SD card is mounted again, there is no way to start app A
directly. But app B can listen to the event that external apps are now
available and then send an event to app A which can then reregister
anything that got broken by unmounting the sd card (e.g. alarm
service).

4) If you need to start your app right after a reboot, app A can no
longer be started after a reboot because the SD card is not mounted
yet. You can simply get rid of the event receiver because step 3
already accomplishes what you need. After reboot, the sd card
eventually is mounted and the external apps will become available. App
B will listen to this even and trigger app A.

Hope this will help some people to move their apps to the sd card. My
app has been used with this feature for 3 months by 400000+ users and
I had no complaints.

Martin Hunke
mobitobi
Gentle Alarm, Sleep Now

--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

No comments:

Post a Comment