我想在 Meghdar.java
中使用共享首选项,这是我的代码,但它不起作用。
public class Meghdar {
private final Context context;
SharedPreferences sp;
String Text;
public Meghdar(Context context) {
super();
this.context = context;
sp = context.getApplicationContext ().getSharedPreferences("AppPreferences", Activity.MODE_PRIVATE);
Text = sp.getString ("text",null);
}}
最佳答案
改成这样:
public class Meghdar {
SharedPreferences sp;
String text;
public Meghdar(Context context) {
super();
sp = context.getSharedPreferences("AppPreferences", Context.MODE_PRIVATE);
text = sp.getString("text", "");
}
}
关于android - 如何在我的类里面使用共享首选项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41576453/