A.java : このクラスには、共有優先権が格納されます。以下のスニペットを使用しています。
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(A.this);
Editor edit = prefs.edit();
edit.putString("Key1", key);
edit.putString("Key2", secret);
edit.commit();
BroadCastReceiver.java :電話を再起動したときに Key1、Key2 の値を取得したい。このために、以下のスニペットを使用しています。
@Override
public void onReceive(Context context, Intent intent) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
String a = prefs.getString("Key1", null);
String b = prefs.getString("Key2", null);
}
クエリ:
この問題は文脈によるものかどうか
出力:
null値を取得しています。他のアクティビティでこの形式を試してみましたが、broadcastReceiver ではnull
値が得られました。
私が正しい方法よりも間違った方法を選択している場合は?