Skip to content

Instantly share code, notes, and snippets.

@kentakang
Last active December 13, 2018 15:28
Show Gist options
  • Save kentakang/987e2364638de1a015d0a308df38124f to your computer and use it in GitHub Desktop.
Save kentakang/987e2364638de1a015d0a308df38124f to your computer and use it in GitHub Desktop.
Kotlin Global Context
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.kentastudio.hanyang">
<application
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=".App">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
</application>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET"/>
</manifest>
import android.app.Application
import android.content.Context
class App : Application() {
companion object {
lateinit var instance: App
private set
}
override fun onCreate() {
super.onCreate()
instance = this
}
fun context(): Context = applicationContext
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment