存储状态数据

保存偏好
        @Override
        protected void onPause(){
                super.onPause();                // Save user preferences. use Editor object to make changes.
                SharedPreferences settings = getSharedPreferences(PREF, 0);
                settings.edit()
                  .putString(PREF_HEIGHT, field_height.getText().toString())
                  .commit();
        }
获取偏好
    // Restore preferences
    private void restorePrefs()
    {
        SharedPreferences settings = getSharedPreferences(PREF, 0);
        String pref_height = settings.getString(PREF_HEIGHT, "");
        if(! "".equals(pref_height))
        {
                field_height.setText(pref_height);
                field_weight.requestFocus();
        }
    }

posted @ 2011-09-17 09:36  jetz  阅读(208)  评论(0编辑  收藏  举报