2010-12-10 9 views
0

doinbackgroundにtabbarを追加する方法asynctask in android?またはスレッドでスプラッシュ画面を実行する方法?私は進行中のダイアログやスプラッシュ画面を表示するには、タブバーが呼び出されるtabbarクラスからロードされます。私はwebservicesを呼び出しています。値を解析するのに時間がかかります。数分は時間がかかるため、プロジェスバーまたはスプラッシュ画面を表示する必要があります。誰も私にこれを実装する方法を教えてもらえますか?誰かがサンプルコードを提供できますか? 私が試したが、そのはあなたがバックグラウンドスレッドとUIメインスレッド間の同期を管理ハンドラを使用する必要があることを行うためには、バックグラウンドスレッドからメインUIスレッドの何も触れることができないdoinbackgroundでtabbarを追加する方法asynctask in android

dlg = ProgressDialog.show(this, "Working..", "Downloading Data...", true, false);  

Thread splashThread = new Thread() { 
     @Override 
     public void run() { 
      try { 

       sleep(100000); 



      } catch (InterruptedException e) { 
       // do nothing 
      } finally { 

      } 
     } 
    }; 
    splashThread.start(); 

答えて

0

を動作していません。

AsyncTaskをサブクラス化するより良い方法は、これを実行すると、すでにバックグラウンドで動作するメソッドとUIで動作するメソッドがあります。これにより、バックグラウンド操作を実行してinmediatly結果を示していることができます...

public class AsynchronousTask extends AsyncTask<Runnable, String, Result> { 

//method executed automatically in the ui event before the background thread execution 
@Override 
    protected void onPreExecute() { 
     //show the splash screen and add a progress bar indeterminate 
    } 

//method executed automatically in the ui event AFTER the background thread execution 
@Override 
    protected void onPostExecute(Result result) { 
     //hide the splash screen and drop the progress bar or set its visibility to gone. 
    } 

//method executed in a background event when you call explicitly execute... 
@Override 
    protected Result doInBackground(Runnable... tasks) { 
Result result; 
     if(tasks != null && tasks.length > 0){ 
      for (Runnable runnable : tasks) { 
       //publishProgress(...); 
       runnable.run(); 
           //result = ... 
       //publishProgress(...); 
      } 
     } 
     return result; 
    } 

} 

http://developer.android.com/reference/android/os/AsyncTask.html

は私が与える戻り値の型が何であるか、これは

+0

...助けここに 希望を続きを読みます例 – mohan

+0

をonPreExecuteとonPostExecuteの中に記述すると、AlertDialogを表示したり、スプラッシュ画面をリフレッシュしたりする必要があります。これらのメソッドはイベントスレッドで実行されるため、onProgressUpdate(int progress)をオーバーライドするとProgressBarを進行状況の更新。この最後にもUiで動いています。 – Franco

関連する問題