0
我正在進行此初始屏幕測試,並實施了一個點擊監聽器,以便可以通過點擊屏幕跳過它。問題在於意圖被調用兩次,因爲加載線程在點擊屏幕時未正確中斷。我做錯了什麼,以及如何避免這個錯誤?如何使用onClickListener禁用線程?
public class SplashScreen extends Activity {
final Thread Loading = new Thread();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
setContentView(R.layout.splashscreen);
ImageView SplashScreenView = (ImageView) findViewById(R.id.SplashScreenAnimation);
SplashScreenView.setBackgroundResource(R.drawable.flashscreenanimation);
AnimationDrawable SplashScreenAnimation = (AnimationDrawable) SplashScreenView.getBackground();
SplashScreenAnimation.start();
RelativeLayout OnTouchSkipScreen = (RelativeLayout)findViewById(R.id.SplashScreenView);
OnTouchSkipScreen.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Loading.interrupt();
Loading.isInterrupted();
Intent SplashScreen = new Intent(SplashScreen.this, HomeScreen.class);
startActivity(SplashScreen);
overridePendingTransition(R.anim.fade_in, R.anim.fade_out);
finish();
}
});
Thread Loading = new Thread() {
public void run() {
try {
sleep(2573);
Intent SplashScreen = new Intent(SplashScreen.this, HomeScreen.class);
startActivity(SplashScreen);
overridePendingTransition(R.anim.fade_in, R.anim.fade_out);
} catch (Exception e) {
e.printStackTrace();
} finally {
finish();
}
}
};
Loading.start();
}
}
爲什麼有兩個加載線程在你的代碼? – Kunu
你是什麼意思? –
如果你檢查你的代碼,你可以看到你聲明瞭'final Thread Loading = new Thread();'兩次。 – Kunu