Reputation: 171
I'm trying to make a loading screen for my app, in MainActivity i have a thread called timer that starts next activity after 5 sec, but for some reason it doesn't show xml... when thread is not started xml is shown normally but as soon as i start thread screen is blank. Thread works, it changes activity but my "logo.xml" isn't shown.
public class MainActivity extends ActionBarActivity {
Thread timer;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.logo);
timer = new Thread(){
public void run()
{
try{
int ltimer =0;
while(ltimer<5000){
sleep(100);
ltimer += 100;
}
startActivity(new Intent("com.JMS.sinktheship.MENU"));
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
finally
{
finish();
}
}
};
timer.run();
}
Upvotes: 0
Views: 49
Reputation: 130
blackbelt is correct, the view is rendered after the onCreate() is completely executed.
I would advise you to start the thread in the onResume instead and (very important) kill the activity when the thread ends by calling the finish() method (otherwise the activity will stay in the activity stack and will be rendered again via the back button).
Upvotes: 0
Reputation: 157467
timer.run();
it is executed in the same thread that call the run method. Probably you wan to call start()
. In your code you are blocking the UI Thread for something like 5 seconds
Upvotes: 1