如何从活动通过上下文活动? [英] How to pass context from activity to activity?
问题描述
我有一个主要活动,并召唤其他活动来显示一些数据。
I have a main activity, and it summons another activity to display some data.
我有我整个的主要活动code。使用专用数据库辅助对象。有没有一种方法,以我的主要活动范围内传递给我的子活动在一个优雅的方式? (即从子类,像 getCallingActivityContext()
)
I have a private database helper object that I use throughout the main activity code. Is there a way to pass the context of my main activity to my sub activity in an elegant way? (ie, from subclass, something like getCallingActivityContext()
)
我总是可以创建新的数据库辅助对象。
I could always create new database helper objects.
推荐答案
扩展应用程序类可以帮助你允许申报/访问全局变量。您可以设置从任何活动的变量的ApplicationContext
和其他活动访问它,而无需使用包。
Extending the Application class helps you to allow declare/access global variables. You can set your variables from any activity to ApplicationContext
and access it from other activity without using bundle.
这篇关于如何从活动通过上下文活动?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!