手记

自定义全局Application

/**
 * Created by Administrator on 2017/1/9 0009.
 */
public class BaseApplication extends Application {
    private static Context mContext;
    private static Handler mHandler;
    private static int mainThreadId;
    @Override
    public void onCreate() {
        super.onCreate();
        mContext = getApplicationContext();
        mHandler =   new Handler();
        mainThreadId = android.os.Process.myTid();
    }

    public static Context getContext() {
        return mContext;
    }

    public static Handler getHandler() {
        return mHandler;
    }

    public static int getMainThreadId(){
        return mainThreadId;
    }
}

最后不要忘了将AndroidManifest.xml文件下的application节点name属性设为我们自定义的Application。

0人推荐
随时随地看视频
慕课网APP