我想在点击启动画面时停止正在运行的线程,如果我不点击屏幕,在线程执行后,它将启动另一个活动。但是得到UnSupportedException
,我该如何解决呢?
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splash);
iImage = (ImageView) findViewById(R.id.iIcon);
splashImage = (ImageView) findViewById(R.id.splash_image);
iImage.setOnClickListener(this);
splashImage.setOnClickListener(this);
}
@Override
protected void onStart() {
super.onStart();
splashTimer = new Thread(new Runnable() {
@Override
public void run() {
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
e.printStackTrace();
}
startActivity(new Intent(SplashActivity.this, LoginAuthenticationActivity.class));
finish();
}
});
splashTimer.start();
}
@Override
public void onClick(View view) {
if(splashTimer.isAlive())
splashTimer.stop();
switch (view.getId()) {
case R.id.iIcon:
startActivity(new Intent(this, AboutUsActivity.class));
break;
case R.id.splash_image:
startActivity(new Intent(this, LoginAuthenticationActivity.class));
break;
default:
break;
}
finish();
}
日志:
01-27 03:27:01.189: W/dalvikvm(1080): threadid=1: thread exiting with uncaught exception (group=0x409c01f8)
01-27 03:27:01.209: E/AndroidRuntime(1080): FATAL EXCEPTION: main
01-27 03:27:01.209: E/AndroidRuntime(1080): java.lang.UnsupportedOperationException
01-27 03:27:01.209: E/AndroidRuntime(1080): at java.lang.Thread.stop(Thread.java:1076)
01-27 03:27:01.209: E/AndroidRuntime(1080): at java.lang.Thread.stop(Thread.java:1063)
01-27 03:27:01.209: E/AndroidRuntime(1080): at com.app.wooqer.SplashActivity.onClick(SplashActivity.java:48)
01-27 03:27:01.209: E/AndroidRuntime(1080): at android.view.View.performClick(View.java:3511)
01-27 03:27:01.209: E/AndroidRuntime(1080): at android.view.View$PerformClick.run(View.java:14105)
01-27 03:27:01.209: E/AndroidRuntime(1080): at android.os.Handler.handleCallback(Handler.java:605)
01-27 03:27:01.209: E/AndroidRuntime(1080): at android.os.Handler.dispatchMessage(Handler.java:92)
01-27 03:27:01.209: E/AndroidRuntime(1080): at android.os.Looper.loop(Looper.java:137)
01-27 03:27:01.209: E/AndroidRuntime(1080): at android.app.ActivityThread.main(ActivityThread.java:4424)
01-27 03:27:01.209: E/AndroidRuntime(1080): at java.lang.reflect.Method.invokeNative(Native Method)
01-27 03:27:01.209: E/AndroidRuntime(1080): at java.lang.reflect.Method.invoke(Method.java:511)
01-27 03:27:01.209: E/AndroidRuntime(1080): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
01-27 03:27:01.209: E/AndroidRuntime(1080): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
01-27 03:27:01.209: E/AndroidRuntime(1080): at dalvik.system.NativeStart.main(Native Method)