1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
//在Android的清单文件做如下申明:
<application android:name=
"com.xyz.MyApplication"
>
</application>
//然后写这个类:
public
class
MyApplication
extends
Application{
private
static
Context context;
public
void
onCreate(){
super
.onCreate();
MyApplication.context = getApplicationContext();
}
public
static
Context getAppContext() {
return
MyApplication.context;
}
}
//调用MyApplication.getAppContext()来静态的获取你应用程序的context。
|