Android MyApplication 建立

Android MyApplication 建立

建立一个基本的类:

在application类中初始化

自定义MyApplication类继承Application;

在基类添加的当前内容面的获取,context=getApplicationContext();可以在全局使用:调用方式:MyApplication.getContext().

public class MyApplication extends Application {

private static Context context;

public static Context getContext() {

return context;

}

@Override

public void onCreate() {

super.onCreate();

context=getApplicationContext();

}

}

告知AndroidManifest.xml 启动时初始化这个基类:com.example.gtkunittest.MyApplication

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/QMUI.Compat"

android:name="com.example.gtkunittest.MyApplication">

相关推荐

孤高的意思
365app下载安装官方免费下载

孤高的意思

📅 08-30 👁️ 4346
如何用电脑写论文?论文写作技巧
365bet苹果版

如何用电脑写论文?论文写作技巧

📅 08-09 👁️ 2066
98世界杯 英格兰队有 10号 吗 是谁呀???
365app下载安装官方免费下载

98世界杯 英格兰队有 10号 吗 是谁呀???

📅 10-28 👁️ 2447