首先新建一个工具类AppContext

import android.content.Context;

public class AppContext extends android.app.Application {
    private static Context appContext;

    @Override
    public void onCreate() {
        super.onCreate();
        appContext = getApplicationContext();
    }

    public static Context getAppContext(){
        return appContext;
    }

    @Override
    public void onLowMemory() {
        super.onLowMemory();
    }
}

再修改manifests中AndroidManifest.xml
再application中加name

android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme"

        android:name=".Utils.AppContext">
Last modification:October 24th, 2020 at 02:51 pm
如果觉得我的文章对你有用,请随意赞赏