Reputation: 433
I am working on android 2.2, In a Application tab of android manifest provide the option of "Allow clear data" to set true or false. But after setting it to False, my application can't disable the button of Clear data in application info of Manage application. I am facing this problem when application contains database in Data/Data/packge-name/databases/.
I have to protect my application database from user.
Upvotes: 43
Views: 28352
Reputation: 1049
Just a trick.
<application
android:manageSpaceActivity="{packageName}.ManageSpaceActivity"
>
In this scenario Android OS will show a Manage Space button in place of clear data.
Upon clicking it will open ManageSpaceActivity.
But
<application
android:manageSpaceActivity=".AnyActivity"
>
If you do this. It will disable the Clear data button.
Trick is to write the Activity name without the full package name.
Upvotes: 3
Reputation: 14984
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
As far as I have been able to tell, this works 100% of the time.
Upvotes: 138
Reputation: 5961
There is no way to prevent the user from clearing your app data. The manifest option you mention is intended for system apps only and you, as a developer, have no way to install system apps.
Please see this discussion for details - particularly this response from Diane Hackborn (Android framework engineer)
Upvotes: 3
Reputation:
AndroidManifest.xml
<application
android:manageSpaceActivity="[packageName].ManageSpaceActivity"
...
...
>
<activity
android:name="[packageName].ManageSpaceActivity"
android:screenOrientation="portrait" />
it will call my activity, but:
public class ManageSpaceActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
finish();
}// onCreate
}
and the Activity is dead at creation, I love tricks :)
Now you can press the "Manage space" as much as you want! :))
- if you need you can do custom data / cache delete at ManageSpaceActivity
, but you can keep your data, which do you want.
Up votes on Jakar answer too pls!
Upvotes: 50