共享preferences KEY_FIRST_RUN不是工作在Android 1.6的? [英] Shared Preferences KEY_FIRST_RUN is not working in android 1.6?

查看:96
本文介绍了共享preferences KEY_FIRST_RUN不是工作在Android 1.6的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用下面的code,检查应用程序第一次运行或不

I am using the following code to check the application is first time running or not

SharedPreferences pref = getPreferences(MODE_PRIVATE);
if (!pref.contains(KEY_FIRST_RUN)) {
    Some operation
}
pref.edit().putBoolean(KEY_FIRST_RUN, false).commit();

它的工作原理所有的Andr​​oid版本,除了安卓1.6

It works all the android versions except android 1.6

请任何一个帮助我的任何错误在我的计划

Please any one help me any error in my program

给我一些建议

推荐答案

对我来说,以下工作:

private static String KEY_FIRST_RUN = "";
private SharedPreferences sharedPreferences;
private SharedPreferences.Editor editor;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    sharedPreferences = getPreferences(MODE_PRIVATE);

    if (!sharedPreferences.contains("KEY_FIRST_RUN")) {
        KEY_FIRST_RUN = "something";
        Log.d("First", "First run!");
    } else {
        Log.d("Second...", "Second run...!");
    }

    editor = sharedPreferences.edit();
    editor.putString("KEY_FIRST_RUN", KEY_FIRST_RUN);
    editor.commit();
}

这篇关于共享preferences KEY_FIRST_RUN不是工作在Android 1.6的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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