IOS
hefeixia
2021-02-18 49f3c1374873f73dbde2983ca0fcf1fb10bfedbf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/*
 * Copyright (c) 2020 WildFireChat. All rights reserved.
 */
 
package com.highdatas.madeasy.patient;
 
import android.content.Context;
import android.os.Handler;
import android.widget.Toast;
import androidx.multidex.MultiDexApplication;
 
public class BaseApp extends MultiDexApplication {
 
    //以下属性应用于整个应用程序,合理利用资源,减少资源浪费
    private static Context mContext;//上下文
    private static long mMainThreadId;//主线程id
    private static Handler mHandler;//主线程Handler
 
    @Override
    public void onCreate() {
        super.onCreate();
 
        //对全局属性赋值
        mContext = getApplicationContext();
        mMainThreadId = android.os.Process.myTid();
        mHandler = new Handler();
    }
 
    public static Context getContext() {
        return mContext;
    }
 
    public static void setContext(Context mContext) {
        BaseApp.mContext = mContext;
    }
 
    public static long getMainThreadId() {
        return mMainThreadId;
    }
 
    public static Handler getMainHandler() {
        return mHandler;
    }
 
    public static void showToast(Context context, String content) {
        showToast(context, content, false);
    }
 
    public static void showToast( String content) {
        showToast(getContext(), content, false);
    }
 
    public static void showToast(Context context, String content, boolean isLong) {
        if (isLong) {
            Toast.makeText(context, content, Toast.LENGTH_LONG).show();
        } else {
            Toast.makeText(context, content, Toast.LENGTH_SHORT).show();
        }
 
    }
}