I'll try my best to explain the basic steps that Android goes through when it starts an application. This is a simplified answer. For more details you probably need to read the Android source code yourself.
Let's start with the user clicking on the launcher icon for your application on the HOME screen. We assume that your application is not currently running:
- Android creates an OS process to host your application (since there isn't already a running OS process for your application).
- Android creates the main (UI) thread and prepares a
Looper
and Handler
for that thread and starts the Looper
.
- Android instantiates your singleton
Application
object and calls onCreate()
on that instance
- Android instantiates the root
Activity
for your application (the one with ACTION=MAIN and CATEGORY=LAUNCHER in the manifest) and calls onCreate()
on that instance
- Android now calls the various other lifecycle calls on your activities based on the standard lifecycle for Android components.
- Once your
Activity
is on screen and in the foreground, UI events and other system events will be dispatched to your application's components.
In general, unless you explicitly create other threads, all of your code will run on the main (UI) thread.