Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does "setContentView" really do?

Tags:

android

In my main activity, I would like to have it set up, so that I first get met by a contentView just showing a background and some text. After X seconds, I want to change to my other view (GLSurfaceView).

This is obviously something I am doing completely wrong.

This is how I've imagined it could've been done (it's all in the onCreate method):

setContentView(R.layout.main);

try {
    Thread.sleep(10000);
} catch (InterruptedException e) {
}

viewer = new Viewer(this);

setContentView(viewer);

Where layout Main is what I want to show at the beginning and Viewer is my GLSurfaceView class.

What happens is that it just goes black for 10 seconds and then it starts loading the objects I've got that is shown through OpenGLES.

There's nothing wrong with the layout Main, since it works if I just erase the lines under where the Thread.sleep takes action. Though, nothing happens before the Thread.sleep is over...

With that said, my questions are following:

  • Why is the contentView not changing until after Thread.sleep is done?
  • What would be an appropiate solution to what I want to achieve?
like image 554
Henrik Avatar asked Dec 18 '11 03:12

Henrik


1 Answers

I'm assuming this in your onCreate() and thats why you are seeing nothing.

The way I would implement this is to start a thread using AsyncTask sleep in the doInBackground and in the onPostExecute set up the new view.

like image 136
Emil Davtyan Avatar answered Sep 28 '22 02:09

Emil Davtyan