I don't want to let Settings clear my app sharedPreference by anyone: is it possible?
-
Did you find a solution? – JJ86 Dec 16 '13 at 10:54
-
I found another way, check my edit. – JJ86 Dec 16 '13 at 10:59
-
but i don't want to keep database on remote server! instead i want to prevent clearing sharedPref. thanks for ans.. – Hardik Dec 16 '13 at 11:10
-
Understand, there is only one answer: is not possible ;-) . – JJ86 Dec 16 '13 at 12:02
-
1i found a way to prevent data being cleared from shared preference...See My Answer ::))) – Hardik Jan 31 '14 at 08:05
3 Answers
hey buddy i found an answer here is a way to prevent data being cleared from Shared Preference
Add android:manageSpaceActivity=".ActivityOfMyChoice" to the application tag of your Manifest like:
<application android:label="MyApp" android:icon="@drawable/icon"
android:manageSpaceActivity=".ActivityOfMyChoice">
Then instead of "Clear Data", there is a button for "Manage Space" which launches ActivityOfMyChoice
it will call my activity and the Activity is finish at creation :)
public class ActivityOfMyChoice extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
finish();
}
}
Now you can press the "Manage space" as much as you want! :)
this method works 100% of the time.
- 17,950
- 2
- 40
- 45
-
2You Sir, deserve a medal. A clean workaround when all say "you cannot do it". Respect – user3041058 Dec 09 '14 at 06:32
-
-
@slayton you are right but there is no other way so we need to do this way :) – Hardik Jan 09 '15 at 06:11
-
-
**@Hardik,** _it's work perfect._ actually **_i read above comments it's not good way/practice, can you please explain what is wrong if we use this?_** – Arbaz.in Aug 31 '18 at 07:00
-
@Arbaz.in As far as nothing wrong with this until you hardly need it but android recommend let user clear the data or you may provide the proper manage space activity to guide your users for what to do when they press clear data. – Hardik Aug 31 '18 at 10:17
I found this similar question:
Shared preferences and files not saved to the SD card will be deleted when the app is uninstalled.
Files saved to the SD card will persists after uninstall, however, the user will have access to read, over-write, and delete these files at will.
If you need truly permanent storage the best way forward would be to store the data remotely on a server that you control.
If you don't care about data, then you can save it on SD Card.
EDIT
I think that BFil answer's is very good on this post, check it.
My final verdict
After long research (for my pure and insane curiosity!), there is no way (at the moment?) to preserve SharedPreference after clear on Settings: the only way is a server vault or Data Backup.
-
i found a way to prevent data being cleared from shared preference...See My Answer ::))) – Hardik Jan 31 '14 at 08:05