I have a question that I have a splash screen in my Android application in which I use a thread to wait 8 seconds, it works fine in 1.6.2.1,2.2,2.3.3, 3.0, 3.1, but it returns an error when I I want to run the same in version 4.0.3 for Android, I don’t know why? Please suggest me the right solution for the same. Below I mentioned the error and my code.
Error Stack:
01-05 10:16:06.417: E/AndroidRuntime(589): FATAL EXCEPTION: Thread-75
01-05 10:16:06.417: E/AndroidRuntime(589): java.lang.UnsupportedOperationException
01-05 10:16:06.417: E/AndroidRuntime(589): at java.lang.Thread.stop(Thread.java:1076)
01-05 10:16:06.417: E/AndroidRuntime(589): at java.lang.Thread.stop(Thread.java:1063)
01-05 10:16:06.417: E/AndroidRuntime(589): at com.shipface.common.SplashScreen$1.run(SplashScreen.java:34)
The code:
public class SplashScreen extends Activity {
Thread splash;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
splash = new Thread(){
@Override
public void run(){
try {
synchronized(this){
wait(4000);
Intent intent = new Intent(SplashScreen.this,HomeActivity.class);
startActivity(intent);
finish();
}
}
catch(InterruptedException ex){
}
finish();
stop();
}
};
splash.start();
}
}
source
share