androidasynchronousoncreateprogram-flow

Wait for user interaction before finishing onCreate()


In my app I set everything up in onCreate and then, start an Async Task which sets about loading all of my resources etc... just after the Async Task starts, I add my splash screen to my layout. When everything has loaded, the splashscreen is dismissed and my Open GL Renderer is revealed underneath.

What I'm attempting to do, is to add a dialog screen (basically, another View class that displays a bitmap). And, I don't want any of the Splash stuff to happen until the user presses taps the screen within my dialog screen.

It would be something like this (Note, this is just an excerpt from my real onCreate but should be enough to illustrate the problem)

public void onCreate(Bundle savedInstanceState){

        SplashScreen splash = new SplashScreen (getApplication(), width, height);
        ConsentDialog consentDialog = new ConsentDialog(getApplication(), width, height);

        //Add the consent dialog
        layout.addView(consentDialog);

        setContentView(layout);

        super.onCreate(savedInstanceState);

        //Splashscreen
        backgroundResources = new MyAsync(newBundle);
        backgroundResources.execute(); 
        layout.addView(splash);
}

However when I run the above, it shows the splash screen, loads everything, then dismisses the splash, leaving the dialog behind.

How can I pause (or something that gives the effect of being paused), the onCreate method just after setContentView until the user has tapped the screen? (Note, I'm waiting for touch event using the onTouch(View v, MotionEvent event) method in my consentDialog object.

Basically, the async shouldn't start until the user taps the screen. If this can't be done, What could I do to achieve something that would give the effect I desire?


Solution

  • How can I pause (or something that gives the effect of being paused), the onCreate method just after setContentView until the user has pressed a key?

    You don't.

    Note, I'm waiting for a keypress using the onTouch(View v, MotionEvent event) method in my consentDialog object

    Put your work that should wait "until the user taps the screen" logic in onTouch(), or in a method invoked from onTouch().