Why is sleeping thread stopping layout showing?

Why does this not draw the layout first, then sleep? It does show the next activity correctly after sleeping, but before sleeping does not show the first screen. This is intended to be a splash screen.

In order, it should: - Set the content view ( show the splash ) - Create the thread. - Run the thread - Thread sleeps - Thread starts the new activity.

Only, it appears it's not happening like that. Any help is much appreciated

package nutterzUK.spinDroid.application;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

public class SpinDroidActivity extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        Thread myThread = new Thread(){
            public void run(){
                try {
                    Intent myIntent = new Intent(SpinDroidActivity.this, NextActivity.class);
                    this.sleep(5000);
                    startActivity(myIntent);
                    finish();
                } catch (InterruptedException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }
        };

        myThread.run();
    }
}

Answers


In fact you aren't creating a concurrent situation. You are executing the run() method in the UI thread.

The call you want to do is

myThread.start();

which launches the Thread concurrently.


Need Your Help

Can't find what assembly contains BusyIndicator

silverlight silverlight-4.0 silverlight-5.0 busyindicator

I had my project written in Silverlight 4. Recently I've reinstalled my system and installed Silverlight 5. But when I re-installed "everything" I got the problem with BusyIndicator. It does look l...

Does HTMl5 tel and sms return any values?

javascript ipad html5 cordova sencha-touch

I am building a sample html5 application which is targeted to run on Iphone,Ipad,Andriod devices , Application contains a contact us feature where it includes 'tel' and 'sms' functionality , Its wo...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.