I have no idea why my app isnt liking the following and would be grateful for any help.
I have a main activity that sets the following onCreate
setContentView(new Splash(this));
Splash being a surfaceview with the following in its constructor
this.setBackgroundDrawable(getResources().getDrawable(R.drawable.splash));
Then I have a thread in Splash that waits 3seconds or 3000 miliseconds.
Then calls the second surfaceview in the main activity
setContentView(new GameCanvas(this));
Everything works fine until it calls the seoncds setContentView, the screen doesnt change, it sticks on the splash screen.
any idea why?
Here is my thread
new Thread(){
public void run(){
try{
Log.e("here", "sleeping");
sleep(3000);
//main being the main activity class
main.killSplash();
//Log.e("here", "KILL SPLASH");
}catch(Exception e){
//
}
}
}.start();
p.s i have a feeling it is because I'm calling t开发者_JAVA百科he switch canvas method from inside a thread
Activities are designed to be different "screens" in your application, and thus you should separate your splash screen's activity from your main game activity. Once an activity has drawn, I don't believe changing the contentView will trigger a redraw. I believe you are only supposed to call setContentView once- from the onCreate method.
Also note that each activity is automatically run in a new thread.
As an aside, you might want to follow some of the Android Developer tutorials. setContentView is primarily for establishing the layout and contents of your activity, usually defined in an XML resource, whereas you seem to be treating it as a means for switching view instances.
精彩评论