I have an app that displays a splash screen. The splash screen activity creates a new Runnable which simply sleeps for 1 second and and then launches the main activity:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.splash);
UKMPGDataProvider.init(this.getApplicationContext(), Constants.DATABASE_NAME);
Thread splashThread = new Thread() {
@Override
public void run() {
try {
sleep(ONE_SECOND_IN_MILLIS);
} catch (InterruptedException e) {
} finally {
Intent intent = new Intent(SplashScreen.this, MainScreen.class);
finish();
startActivity(intent);
}
}
};
splashThread.start();
}
Is it OK to launch the main activity (and therefore the whole app except for the splash screen) on this new thread?
We hear a lot about the “UI thread” in Android. Does this new thread now become the UI thread, or is the UI thread special in some way?
Yes, that’s fine.
startActivity(intent)asks the system to launch your mainActivity. You’re not actually loading it yourself in the thread you call that from.