Android-设置全局变量


public class BaseContext extends Application {
    private static Context mContext;
 
    public void onCreate() {
        super.onCreate();
        mContext = getApplicationContext();
    }
    public static Context getContext(){
        return mContext;
    }

最后在清单文件的Application中加入一个name属性:
例如:
android:name=".utils.BaseContext"

在需要调用的方法写:

BaseContext.getContext()

发布了15 篇原创文章 · 获赞 5 · 访问量 359

猜你喜欢

转载自blog.csdn.net/weixin_44059750/article/details/105100371