0
我的應用程序有一個帶有動畫標誌的啓動畫面(使用線程),然後顯示菜單頁面。啓動畫面在設置菜單頁面之前顯示白色屏幕然後變黑。
現在我想在我的閃屏中做一些背景活動。這是我想要將一些圖像轉換爲字符串等。
我已經將代碼放在我的onCreate()函數中。但問題是,而不是閃屏我看到一個空白的白色屏幕,然後黑屏。然後在某個時間之後,菜單頁面照常顯示。
如果我評論後臺處理代碼,它的功能完美。此外,後臺代碼工作正常。只有他們不能一起正常工作。 logcat中沒有錯誤,我無法知道什麼是錯誤的。
請幫忙。它非常緊急......謝謝。
閃屏Java代碼
public class Splash extends Activity {
protected int _splashTime = 10000;
private Thread splashTread;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//MakeFolder();
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
//Remove notification bar
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.splash);
MakeFolder();
ImageView IM =(ImageView)findViewById(R.id.imageView2);
final Animation mobianim = AnimationUtils.loadAnimation(this, R.anim.mobianim);
IM.setAnimation(mobianim);
mobianim.setDuration(1000);
animate();
// AnimateLogo();
final Splash sPlashScreen = this;
// thread for displaying the SplashScreen
splashTread = new Thread() {
@Override
public void run() {
try {
synchronized(this){
wait(_splashTime);
}
} catch(InterruptedException e) {}
finally {
finish();
Intent i = new Intent();
i.setClass(sPlashScreen, MenuPg.class);
startActivity(i);
// stop();
}
}
};
splashTread.start();
/*
**Code for doing background things**
*/
}
public void MakeFolder(){
File direct = new File(Environment.getExternalStorageDirectory() + "/MyFolder");
if(!direct.exists())
{
if(direct.mkdir()){ //directory is created;
}
}
}
@Override
public boolean onTouchEvent(MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_DOWN) {
synchronized(splashTread){
splashTread.notifyAll();
}
}
return true;
}
public void animate(){
ImageView IV1=(ImageView)findViewById(R.id.imageView1);
AlphaAnimation alphaAmin = new AlphaAnimation(0,1);
IV1.setAnimation(alphaAmin);
alphaAmin.setDuration(5000);
}
}
你可以嘗試刪除同步(這個)部分嗎?無論如何,你正在做的事情並不需要同步。您也可以在UI線程上發佈延遲的可運行內容(完成後,開始下一個活動)。你可以像這樣將它發佈到你的imageView上:IV1.postDelayed(runnable,_splashTime); – tiguchi
偏離主題,但:http://cyrilmottier.com/2012/05/03/splash-screens-are-evil-dont-use-them/ –