Вопрос

Such a simple thing but I'm having a huge problem with it.

EDIT: I want my ProgressDialog to run while other classes are running - NOT be called within an asyncTask, as there are multiple asyncTasks being called.

My main activity (index) calls another class, aTask, which calls an AsyncTask to grab some data from Yelp. When aTask returns the data, index starts a new activity.

I want index to show a progress dialog while aTask is running. So I use the answer from here to put a progress dialog in index.

However, the progress bar is only shown after aTask finishes, which completely defeats the purpose.

Here is the code:

        mButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            ProgressDialog.show(IndexActivity.this, "Loading", "Wait while loading...");
            ATask at = new ATask(preferencesMap, IndexActivity.this);

            final ArrayList<Business> locations = at.getLocations();

            Intent intent = new Intent(IndexActivity.this, BTask.class);
            intent.putExtra("EXTRA_DIRECTIONS_STEPS", locations);
            intent.putExtra("EXTRA_MAP_LOCATIONS", locations);
            startActivity(intent);
        }
    });
Это было полезно?

Решение 2

This should be the definitive answer, at least for my situation.

Easy to implement, works even if you're calling asyncTasks, etc.

Другие советы

Most working thing is to add the Progress Dialog to a real Async task(s) not some synchronous task. Your computer needs time to execute the Progress Dialog script and cannot, if the task is not in a thread or another Async event. Look other questions on SO and always there is a thread.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top