私は、次のコードを使用して、私の設定からいくつかの値を取得しようとする場合:ここでgetBaseContext()を使用できないのはなぜですか?
import android.content.SharedPreferences;
import android.preference.PreferenceManager;
import android.content.*;
public class TCPdumpHandler {
public void getPreference() {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getBaseContext());
Boolean checkboxPreference = prefs.getBoolean("checkboxPref", true);
}
}
しかし、エラーは次のとおりです。The method getBaseContext() is undefined for the type TCPdumpHandler
あなたは私に理由を教えてください。
[あなたは 'getBaseContext()'を全く使わないでください(http://stackoverflow.com/questions/1026973/android-whats-the-difference-between-the-various-methods-to-get- (なぜなら、これは初心者の質問であるため、あなたはおそらく分かりません)*。むしろ活動の文脈に固執する。 –