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.
我在主要活动中创建了我的数据库助手类的实例。
我想从可以更新该数据库的任何其他活动中访问该实例。我已经用getApplicationContext()as创建了一个实例,context但它仍然没有在另一个活动中显示该实例。
getApplicationContext()
context
您可以在应用程序文件上创建数据库,而不是主活动。
然后你可以从任何地方访问它,而不是特定的活动。
应用程序
public class ApplicantApp extends Application{ private static Database yourdatabasevariable; }
另一个活动
public class ActivityA{ Application.yourdatabasevariable; }