0
我正在嘗試通過單擊活動的屏幕來找到跳過閃屏的方法。這是我來到,它的工作原理。問題是,我點擊後,新的活動被調用,布爾假默認如果再次運行,意圖被調用兩次。我究竟做錯了什麼?如何使用布爾值停止onClick線程?
RelativeLayout OnClickSkipScreen = (RelativeLayout)findViewById(R.id.SplashScreenView);
OnClickSkipScreen.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
OnClickSkip = true;
/*Loading.interrupt();
Intent SplashScreen = new Intent(SplashScreen.this, HomeScreen.class);
startActivity(SplashScreen);
overridePendingTransition(R.anim.fade_in, R.anim.fade_out);
finish();*/
}
});
Thread Loading = new Thread() {
@Override
public void run() {
if (!OnClickSkip) {
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();
}
} else if (OnClickSkip) {
try {
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();
}
你在哪裏申報'OnClickSkip'?你堅持它的數據嗎? – Elltz
緊跟在活動類之後:Thread Loading = new Thread();和 volatile boolean OnClickSkip = false;我怎樣才能讓數據持久?你的意思是使布爾真正的狀態是永久的,對嗎? –