如何防止在设置中清除共享首选项 [英] How to prevent a shared preference from being clear in setting

查看:78
本文介绍了如何防止在设置中清除共享首选项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不想让设置清除任何人的应用程序sharedPreference:有可能吗?

I don't want to let Settings clear my app sharedPreference by anyone: is it possible?

推荐答案

嘿,伙计,我发现这里的答案是一种防止从共享首选项中清除数据的方法

hey buddy i found an answer here is a way to prevent data being cleared from Shared Preference

android:manageSpaceActivity=".ActivityOfMyChoice"添加到清单的application标签中,例如:

Add android:manageSpaceActivity=".ActivityOfMyChoice" to the application tag of your Manifest like:

    <application android:label="MyApp" android:icon="@drawable/icon" 
                 android:manageSpaceActivity=".ActivityOfMyChoice">

然后代替"Clear Data",有一个"Manage Space"按钮启动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! :)

此方法在100%的时间内有效.

this method works 100% of the time.

这篇关于如何防止在设置中清除共享首选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆