2013-01-24 46 views
0

我有一个调用Web服务,而异步任务执行我想要显示的加载屏幕解析XML显示loadingscreen而异步任务

@Override 
protected void onPreExecute(){ 
super.onPreExecute(); 
time = System.currentTimeMillis(); 
} 
protected Boolean doInBackground(Integer... params) { 
    //code 
} 

protected void onPostExecute(Boolean result) { 
super.onPostExecute(result); 
    difftime = System.currentTimeMillis() - time; 
} 

这个异步任务,但加载屏幕异步任务之前完成完成如果我做这样的

 super.onCreate(savedInstanceState); 
     setContentView(R.layout.loading_screen); 

      final CallWebService callTarif = new CallWebService(6,sett.getDeviceId()); 
      callTarif.execute(); 

new Handler().postDelayed(new Runnable(){ 
     @Override 
      public void run() { 

       LoadingScreen.this.finish(); 
       Intent intent = new Intent(LoadingScreen.this, NextActivity.class); 
            startActivity(intent);    
      } 

     } 
     },callTarif.difftime); 

回答

0

其实postDelayed正在完成的AsyncTask之前调用。

只要把这些代码行

LoadingScreen.this.finish(); 
Intent intent = new Intent(LoadingScreen.this, NextActivity.class); 
startActivity(intent);  

中的AsyncTask的opPostExecute()

protected void onPostExecute(Boolean result) { 
super.onPostExecute(result); 

    difftime = System.currentTimeMillis() - time; 
    LoadingScreen.this.finish(); 
    Intent intent = new Intent(LoadingScreen.this, NextActivity.class); 
    startActivity(intent);  
} 

,并删除处理器new Handler().postDelayed(new Runnable(){

0

启动加载屏幕onPreExecute方法和杀死它onPostExecute异步任务

0

无需使用处理器的显示使用异步任务访问webservice时加载的方法。使用AsyncTask的onPreExecute()方法显示加载屏幕并在onPostExecute内完成,因为此方法在doInBackground执行完成时调用。将代码代码更改为:

 @Override 
     protected void onPreExecute() { 
      // show loading bar here 
     } 
@Override 
     protected String doInBackground(String... params) { 
       // do network operation here 
      return null; 
     }  

     @Override 
     protected void onPostExecute(String result) {  
      // dismiss loading bar here   
     } 
+0

我必须显示带有幻灯片放映的加载屏幕,而不是加载栏 –