Last active
September 17, 2023 04:20
-
-
Save rvprasad/7c2075590b035c2fec9a5766dd48b68c to your computer and use it in GitHub Desktop.
Initialization Order of Android Components
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | |
xmlns:tools="http://schemas.android.com/tools" | |
package="com.example.dummy"> | |
<application | |
android:label="@string/app_name" | |
tools:targetApi="31" | |
android:name=".MyApplication"> | |
<provider | |
android:name=".MyContentProvider" | |
android:authorities="com.example.dummy.fileprovider" | |
android:enabled="true" | |
android:exported="true"/> | |
<activity | |
android:name=".MainActivity" | |
android:exported="true" | |
android:label="@string/app_name"> | |
<intent-filter> | |
<action android:name="android.intent.action.MAIN" /> | |
<category android:name="android.intent.category.LAUNCHER" /> | |
</intent-filter> | |
</activity> | |
</application> | |
</manifest> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@RunWith(AndroidJUnit4::class) | |
class ExampleInstrumentedTest { | |
@Test | |
fun test() { | |
ActivityScenario.launch(MainActivity::class.java) | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
attachBaseContext(MyApplication) called | |
onCreate(MyContentProvider) called | |
onCreate(MyApplication) called | |
attachBaseContext(MainActivity) called | |
onCreate(MainActivity) called | |
onStart(MainActivity) called |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MainActivity : ComponentActivity() { | |
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate(savedInstanceState) | |
Log.d(MyApplication.TAG, "onCreate(MainActivity) called") | |
Thread.sleep(1000) | |
} | |
override fun onStart() { | |
super.onStart() | |
Log.d(MyApplication.TAG, "onStart(MainActivity) called") | |
Thread.sleep(1000) | |
} | |
override fun attachBaseContext(newBase: Context?) { | |
super.attachBaseContext(newBase) | |
Log.d(MyApplication.TAG, "attachBaseContext(MainActivity) called") | |
Thread.sleep(1000) | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MyApplication: Application() { | |
override fun onCreate() { | |
super.onCreate() | |
Log.d(TAG, "onCreate(MyApplication) called") | |
Thread.sleep(1000) | |
} | |
override fun attachBaseContext(base: Context?) { | |
super.attachBaseContext(base) | |
Log.d(TAG, "attachBaseContext(MyApplication) called") | |
Thread.sleep(1000) | |
} | |
companion object { | |
const val TAG = "MyApplication" | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MyContentProvider : ContentProvider() { | |
override fun onCreate(): Boolean { | |
Log.d(MyApplication.TAG, "onCreate(MyContentProvider) called") | |
Thread.sleep(1000) | |
return true | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment