2016-08-16 1 views
0

アンドロイドスタジオエミュレータでうまく動作するコードがありますが、実際のデバイスで実行すると動作が停止します。Sharedpreferencesはアプリの動作を停止させます

ご案内、よろしくお願いいたします。私はこのコードを無効にした場合、それは何のエラーを持っていないことを

public class Login extends AppCompatActivity { 

    public static final String MyPREFERENCES = "MyPrefs" ; 
    public static final String Mobile = "mobileNum"; 
    public static final String ActivationCode = "activationCode"; 
    public static final String SecurityCode = "securityCode"; 

    SharedPreferences sharedpreferences; 

    @Override 
    public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 

    sharedpreferences = getSharedPreferences(MyPREFERENCES, Context.MODE_PRIVATE); 
    String mobileNumber = sharedpreferences.getString(Mobile, null); 
    String activationCode = sharedpreferences.getString(ActivationCode, null); 
    String securityCode = sharedpreferences.getString(SecurityCode, nu 

    activationCode = random(); 

    SharedPreferences.Editor editor = sharedpreferences.edit(); 
    editor.putString(ActivationCode, activationCode); 
    editor.commit(); 
    } 
} 

注:ここでは

は、私のコードの一部です。

SharedPreferences.Editor editor = sharedpreferences.edit(); 
editor.putString(ActivationCode, activationCode); 
editor.commit(); 
+0

「MyPREFERENCES」はどこですか? –

+0

ええ、スタックトレースを含めるべきでしょう。 –

+0

関数random()は何を返しますか? –

答えて

1

コミットの代わりにapplyを使用します。コミットがブロックされています。

+0

よろしくお願いします。 – Saeid

関連する問題