0

円形の不確定なプログレスバーを表示してから、スレッドを実行します。これには数秒かかる場合があります (メソッド内で別の AsyncTask が実行されているため、おそらく AsyncTask を試しましたが、機能しませんでした)。ただし、progressBar は Thread が完了した直後にのみ表示されます。ユーザーが何かが起こっていることを確認できるように、スレッドを実行する前にそれを表示する方法は?

編集:コードはかなり複雑なので、長い説明なしですべてを添付することはできませんが、コードの重要な部分を添付しようとします

  //this is the Thread class
  private static final class LoadingMolecules extends Thread{
        private Intent intent;
        private ArrayList<Integer> groups;
        Context context;
        QuizProvider quizProvider;

    public LoadingMolecules (Intent intent,ArrayList<Integer> groups, Context context ){
        this.intent = intent;
        this.groups = groups;
        this.context = context;
    }

    @Override
    public void run() {
        quizProvider = new QuizProvider(groups, context);
        //inside next method is the asyncTask
        quizProvider.loadAllCompounds();
    }


}


//there is the code running
progressBar.setVisibility(View.VISIBLE);
        LoadingMolecules lm = new LoadingMolecules(intent, groups, this);
        lm.start();
        try {
            lm.join();
        }catch (InterruptedException ignore){

        }
        intent.putExtra("quizProvider", lm.quizProvider);
        startActivity(intent);
        finish();
4

1 に答える 1