为什么 sharedpreference 提交方法在我重写的方法中不起作用?

why sharedpreference commit method doesn't work in my overrided method?

我的应用程序中有一个闪屏 activity,它首先检查以找出应用程序 运行 并首先显示用户界面语言选择对话框 运行 然后尝试将其存储在首选项中但我的代码不起作用。
我想将其保存在我的设置 activity 中存在的密钥中,该密钥扩展 preferenceactivity.when 我转到设置 activity 我看到没有任何变化。
我想知道为什么 sharedpreference 提交方法在我覆盖的方法中不起作用?

package com.myapps.qoshuqlar;

import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.PreferenceManager;
import com.myapps.qoshuqlar.UILanguageSettingDialog.DialogListener;
import android.support.v4.app.FragmentActivity;
import android.widget.Toast;

public class SplashScreen extends FragmentActivity implements DialogListener {
SharedPreferences sharedpref;
final Context context=this;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.layout_splashscreen);
    //setting default values for main settings
    PreferenceManager.setDefaultValues(this,R.xml.preferences,false);
    //getting application first run from sharedpreferences
    sharedpref= PreferenceManager.getDefaultSharedPreferences(this);;
    final boolean applicationfirstrun=sharedpref.getBoolean("applicationfirstrun",true);
    //splashscreen thread
    Thread t=new Thread(new Runnable() {
        @Override
        public void run() {
            try {
                //this if_block check to know the language is setted or not
                if(applicationfirstrun){        
                    UILanguageSettingDialog uilsd=new UILanguageSettingDialog();
                    uilsd.show(getSupportFragmentManager(),"uilsd");
                }
                else{
                    Intent i = new Intent(SplashScreen.this,MainMenu.class);
                    startActivity(i);
                }
            } catch (Exception e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }

        }
    }
                        );
    t.start();
}

//on dialog positive click
@Override
public void onDialogPositiveClick(UILanguageSettingDialog dialog, int item) {
    switch (item) {
    case 0:
        sharedpref.edit().putString("pref_key_ui_language","sat");
        sharedpref.edit().commit();
        Toast.makeText(this,"sat", Toast.LENGTH_LONG).show();
        break;
    case 1:
        sharedpref.edit().putString("pref_key_ui_language","nat");
        sharedpref.edit().commit();
        Toast.makeText(this,"nat", Toast.LENGTH_LONG).show();
        break;
    case 2:
        sharedpref.edit().putString("pref_key_ui_language","fa");
        sharedpref.edit().commit();
        Toast.makeText(this,"fa", Toast.LENGTH_LONG).show();
        break;
    case 3:
        sharedpref.edit().putString("pref_key_ui_language","en");
        sharedpref.edit().commit();
        Toast.makeText(this,"en", Toast.LENGTH_LONG).show();
        break;
    }

        Intent i=new Intent(SplashScreen.this,MainMenu.class);
        startActivity(i);


}

}

尝试使用此对象来简化您对共享首选项的使用。这样您就可以避免导致您保存的价值丢失的常见错误。 https://github.com/kcochibili/TinyDB--Android-Shared-Preferences-Turbo