Splash screen thread throwing errors. How to resolve? (Code & Errors Included)
I have some errors with my splash screen that I have been working on for a while and can't figure out. Is there a better way to time my splash screen than a thread? What's wrong with my current thread? Can you see an issue with my media player object?
I've posted the guts of my splash class. Hopefully I can get some direction on these issues. This works when I run the app but I just don't want to have errors.
-------------------------Code------------------------------
@Override
public void onCreate(Bundle savedInstanceState) {
......onCreate, hide window, and setting content view.......
// Play Sound for startup
mpSplash = MediaPlayer.create(this, R.raw.splashscream);
mpSplash.start();
final Splash splash = this;
logoTimer = new Thread(){
public void run(){
try {
synchronized(this){
// Wait given period of time or exit on touch
wait(4500);
}
}
catch(InterruptedException ex){
ex.printStackTrace();
}
finish();
mpSplash.stop();
mpSplash.reset();
//mpSplash.release();
//mpSplash.release();
// Run next activity
Intent intent = new Intent();
intent.setClass(splash, Game.class);
startActivity(intent);
stop();
}
};
logoTimer.start();
}
// Splash screen touch events
@Override
public boolean onTouchEvent (MotionEvent evt)
{
if(evt.getAction() == MotionEvent.ACTION_DOWN)
{
// Stop the introduction sounds
mpSplash.stop();
mpSplash.reset();
//mpSplash.release();
//mpSplash.release();
synchronized(logoTimer){
logoTimer.notifyAll();
}
}
return true;
}
------------------------------Errors-----------------------------
09-11 21:50:04.644: ERROR/MediaPlayer(460): stop called in state 1
09-11 21:50:04.644: ERROR/MediaPlayer(460): error (-38, 0)
09-11 21:50:04.654: ERROR/global(460): Deprecated Thread methods are not supported.
09-11 21:50:04.654: ERROR/global(460): java.lang.UnsupportedOperationException
09-11 21:50:04.654: E开发者_C百科RROR/global(460): at java.lang.VMThread.stop(VMThread.java:85)
09-11 21:50:04.654: ERROR/global(460): at java.lang.Thread.stop(Thread.java:1379)
09-11 21:50:04.654: ERROR/global(460): at java.lang.Thread.stop(Thread.java:1344)
09-11 21:50:04.654: ERROR/global(460): at com.ss.lastzombie.Splash$1.run(Splash.java:61)
Thanks!!
Don't call stop()
in your thread. That's a deprecated method (it leads to instability in the VM) and is not needed. (The thread will exit when the run()
method returns). You probably intended to call finish()
for the splash activity. That would make sense.
Just for form's sake, you might want to call startActivity
and finish
on the main thread instead of your worker thread. To do this, post a Runnable using runOnUIThread()
and call those two methods from the Runnable.
精彩评论