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.
如何使应用程序上下文对应用程序中的所有类可用?我的支持类需要能够访问它才能访问资源。
最佳答案:将 a 传递Context给您的支持类的方法,因为应用程序上下文可能适用于您的特定情况,也可能不适用于您的特定情况。例如,您会注意到,Android 中的许多支持类都采用这种方法,并且遵循平台开发人员制定的模式通常是一个好主意。
Context
可能可以容忍的答案:使用静态数据成员来保存对Application对象的引用。请非常小心,不要在此过程中引入内存泄漏。
Application