Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Persist Data After Uninstall

I have to persist 2 strings for my application even after the application is uninstalled. Regarding that the end users don't have SD cards for their devices and they don't have internet connection, how could I persist those 2 strings even after the app is uninstalled?

I would highly appreciate any response. Thanks

like image 551
Laura Avatar asked Oct 30 '13 13:10

Laura


2 Answers

Phones internal storage is also treated as an "SD card". If you create a folder and save it in a text file, it should be safe given user does not manually delete folders after uninstall.

Please check out a section "Saving files that should be shared" in the following web page. Making a file that persists after uninstall entails making it available to other apps/user to read and modify. If those file options aren't intended, you should consider an alternative app design.

http://developer.android.com/guide/topics/data/data-storage.html#filesInternal

After re-install, your app can access the created public directory by using the following function:

public static File getExternalStorageDirectory ()

Regarding the function above, per Google:

Note: don't be confused by the word "external" here. This directory can better be thought as media/shared storage. It is a filesystem that can hold a relatively large amount of data and that is shared across all applications (does not enforce permissions). Traditionally this is an SD card, but it may also be implemented as built-in storage in a device that is distinct from the protected internal storage and can be mounted as a filesystem on a computer.

Also, Google recomments placing shared files into a an existing public directory as to not pollute user's root namespace.

like image 32
C0D3LIC1OU5 Avatar answered Sep 30 '22 06:09

C0D3LIC1OU5


Unless you're targeting VERY old phones, you don't need to worry about not having external storage. As long as you use Environment.getExternalStorageDirectory() as your reference, you shouldn't have a problem, though if you're absolutely concerned about this you can check if the external storage doesn't exist and then opt to go to internal storage. Check out this link from the developer docs for a little more insight.

If External truly isn't available, you could then save to Internal memory, but you will have to declare a new permission for that, which may ward off some people.

like image 93
Andrew Schuster Avatar answered Sep 30 '22 05:09

Andrew Schuster