I am trying to make my Android application run some code when run from the launcher, BEFORE launching into an activity. That is to say I want my app to start with a Sub Main
as opposed to going into an Activity first.
Essentially, in pseudo, I want to do something like this:
void main() {
doSomeInitializationStuff();
startActivity(myFirstActivity);
}
According to this question, it looks like Android does not have this concept literally. So I was looking at creating an invisible Activity as my entry point, but cannot figure out how to make an activity invisible. I've tried these two methods, which seem to be the only ones coming up in my searches, but they don't seem to actually do anything...
this.setVisible(false);
this.setTheme(android.R.style.Theme_Translucent_NoTitleBar);
Instead of creating an invisible activity you can create a splash activity and start all your initializations there .
I have not tried this but you can extend the application class and use onCreate in your application class to initialize what you need.
Here is the JavaDoc for onCreate of the application class
You will need to let the app know that you are using a custom application class by using the the android:name parameter in the tag of the Android manifest file.