Android equivalent: void main () / Sub Main?

I am trying to get an Android application to run some code on startup from the launchpad before launching into action. That is, I want my application to start with Sub Main, and not in the first place.

Essentially, in pseudo, I want to do something like this:

void main() {
    doSomeInitializationStuff();

    startActivity(myFirstActivity);
}

According to this question , it seems that Android does not have this concept literally. Therefore, I looked at creating invisible activity as an entry point, but I cannot figure out how to make activity invisible. I tried these two methods, which seem to be the only ones that appear in my searches, but they don't seem to do anything ...

this.setVisible(false); this.setTheme(android.R.style.Theme_Translucent_NoTitleBar);

+3
source share
3 answers

.

, onCreate , , .

JavaDoc onCreate

/**
 * Called when the application is starting, before any other application
 * objects have been created.  Implementations should be as quick as
 * possible (for example using lazy initialization of state) since the time
 * spent in this function directly impacts the performance of starting the
 * first activity, service, or receiver in a process.
 * If you override this method, be sure to call super.onCreate().
 */
public void onCreate() {
}

, , android: name Android.

+1

Android SplashScreen, , SplashScreen , ,

0

One option is not to have invisible activity, but SplashScreen. This has the advantage that the user already sees that something happens when the application starts, so that he does not have the impression that he is not working. For example, see, For example, this class ; you should put doSomeInitStuff () on line 54

Otherwise, I think you can simply not load the layout in the onCreate()first action, and then move from there.

0
source

Source: https://habr.com/ru/post/1795412/


All Articles