您的当前位置:首页正文

Android中获取全局Context

2024-11-09 来源:个人技术集锦

package Util;

import android.app.Application;
import android.content.Context;

public class MyApplication extends Application {
private static Context context;
@Override
public void onCreate() {
// TODO Auto-generated method stub
context = getApplicationContext();
}
public static Context getContext(){

return context;
}
}

//别忘记在androidManifest.xml文件中<application>标签中指定能属性该类的全路径
//如android:name="Util.MyApplication"
显示全文