Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一个向 mysql db 发送一些信息的类。我想从这个类中使用 Shared Preferences 方法,但它们属于活动类。我的类扩展了 AsyncTask,所以我不能扩展另一个。我试图创建一个活动实例并使用它,但我的程序已经停止。像这样的东西:
Activity a1 = new Activity(); SharedPreferenecs loginInfo = a1.getSharedPreferences("MyKid", 0);
ETC ..
Activity在非 Activity 类的构造函数中传递您的上下文。
Activity
然后使用
mContext.getSharedPreferences("MyKid", 0);