开发者

Splash screen before dialog message

I want to have a splash screen show up for a few seconds before a dialog pops up. However when I load my app the dialog and the background screen show up at the same time. What can I do to show the background image of my splash.xml before the dialog appears.

Thread waitabit=new Thread(){
public void run(){
try{
    sleep(2000);
}catch(Exception e){
    e.printStackTrace();

}

    }
};waitabit.start();

Putting the above before my dialog just makes it dark for 2 seconds before showing everything all at once. Calling my dialog inside of the thread causes and error because we开发者_开发百科 cant put dialogs in a thread.

Thanks


Try putting the above code in an AsyncTask so that the UIThread does not sleep.

new AsyncTask<Object, Void, Void>() {

    @Override
    protected void onPreExecute() {
        // show background image
    }

    @Override
    protected Void doInBackground(Object... params) {
        new Thread() {
            @Override
            public void run() {
                try {
                    Thread.sleep(2000);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }.run();
        return null;
    }

    @Override
    protected void onPostExecute(Void result) {
        // open dialog
    }

}.execute();


This link has a pretty good solution on how to show a splash screen and call a handler once the splash screen is finished (i.e. this would allow you to display your dialog box).


How about an activity to show the splash screen that, in turn, launches the activity with the dialog?

http://www.codeproject.com/KB/android/AndroidSplash.aspx


Try this in your onResume:

Runnable myRunnable = new Runnable(){
            @Override
            public void run() {
                // do your dialog
            }};
Handler myHandler = new Handler();
long delayMillis = 5000; // 5 seconds
myHandler.postDelayed(myRunnable, delayMillis);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜