[Kotlin]アプリケーションコンテキストの入手方法
アプリケーションクラス
≪アプリケーション|Application|emdw≫:アプリケーションの実行時に最初に実行されます.インスタンスは1つだけです.
Application Context:アプリケーションの実行中にメンテナンスを行い、クラス後の実行時のみ変更します.
getApplicationContext():アプリケーションのグローバルステータス情報を返す
アプリケーションの継承 MainApplication.java アプリケーションContext:静的と宣言し、現在実行中のアプリケーションContextをバインドします. onCreate():アプリケーションが最初に実行されたときに呼び出されます. MainApplicationの呼び出し
AndroidManifest.xmlは明示的な設定が必要です.関数:MainApplicationを呼び出します.getAppContext() リファレンス Android Kotlinアプリケーションプログラミングガイド
≪アプリケーション|Application|emdw≫:アプリケーションの実行時に最初に実行されます.インスタンスは1つだけです.
Application Context:アプリケーションの実行中にメンテナンスを行い、クラス後の実行時のみ変更します.
getApplicationContext():アプリケーションのグローバルステータス情報を返す
アプリケーションの継承
import android.app.Application;
import android.content.Context;
public class MainApplication extends Application {
private static Context applicationContext;
public static Context getAppContext() {
return applicationContext;
}
@Override
public void onCreate() {
super.onCreate();
applicationContext = getApplicationContext();
}
}
AndroidManifest.xmlは明示的な設定が必要です.
<application
android:name=".MainApplication"
...
</application>
Reference
この問題について([Kotlin]アプリケーションコンテキストの入手方法), 我々は、より多くの情報をここで見つけました https://velog.io/@pjhyng0125/Kotlin-Application-클래스-getApplicationContext-반환テキストは自由に共有またはコピーできます。ただし、このドキュメントのURLは参考URLとして残しておいてください。
Collection and Share based on the CC Protocol