我是android開發新手。 我試圖加載我想這樣做異步,使得閃屏顯示出來,直到當我運行貝盧閃屏犯規顯示了網絡操作completes.Now一些網絡數據,而它顯示了標題欄空白屏幕處於絞刑狀態。佈局在Android的asynctask期間被吊死
我已標記清單文件,本次活動的LAUNCHER爲好。你能告訴我什麼是正確的方法嗎?
這裏是我的啓動畫面代碼。
public class SplashScreen extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
super.onCreate(savedInstanceState);
setContentView(R.layout.splash);
try{
AsyncTask<Void, Void, HukumNamaDetails> async=new URLReader(splashScreen).execute();
hdetails=async.get();
splashScreen.saveImage(currdate);
}
catch(InterruptedException e) {} catch (ExecutionException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
finally {
System.out.println("In finally");
finish();
//start a new activity
Intent i = new Intent();
i.putExtra("hdetails", new HukumNamaDetails(hdetails.getHukumnama_punjabi()
,hdetails.getPunjabi_vyakhya(),hdetails.getEnglish_translation()));
i.setClass(splashScreen, Daily_HukumNama.class);
startActivity(i);
}
}
//Function that will handle the touch
@Override
public boolean onTouchEvent(MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_DOWN) {
synchronized(splashTread){
splashTread.notifyAll();
}
}
return true;
}
}
感謝 愛瑪
,因爲你在呼喚[AsyncTask.get()](http://developer.android.com/reference/android/os/AsyncTask.html#get%28%29),這使得UI線程等待,直到'doInBackground'執行不完整 – 2013-02-19 04:49:40