Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6809993
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T20:09:09+00:00 2026-05-26T20:09:09+00:00

I have an activity, composed of an AsyncTask aiming to launch a request when

  • 0

I have an activity, composed of an AsyncTask aiming to launch a request when the user clicks on the button. I have been looking for answers, but I didn’t find the same problem, or it didn’t the same for me. The code is doing what I want, but the ProgressDialog looks blocked as the spinner is not turning sometimes (almost all the time).

When I click on the button :

AsyncTask is launched -> showDialog() is called onPreExecute -> startSearch ( SearchManager launches a new AsyncTask with in the doInBackground there is a heavy call with network ) -> doInBackground in Activity waits for SearchManager to be loaded -> display.

Code for button :

button_search.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
                new SearchTask().execute();

            }
        });

Code for AsyncTask in Search Activity :

private class SearchTask extends AsyncTask<Void,Void,Void>{

        @Override
        protected void onPreExecute(){
            showDialog(DIALOG_LOADING_ID);

            searchManager.startSearch();
        }

        @Override
        protected Void doInBackground(Void... params) {


            while(searchManager.isLoading()){
                try {Thread.sleep(150);} catch(Exception e){};
            }


            return null;
        }

        @Override
        protected void onPostExecute(Void ret){
            try {dismissDialog(DIALOG_LOADING_ID);} catch (Exception e){};

            if ( searchManager.errorOccurred() ){
                //Error
            } else {
                //No Error

            }   
        }

Code for SearchManagerAsyncTask : which is directly launched by startSearch

protected class SearchAsync extends AsyncTask <Void,Void,Void>{

        @Override
        protected Void doInBackground(ComSearchAds... datas) {
            global.getDataManager().doSearch();
                        //... When finished
                        setIs_loading(false);
                }
}

I’m apparently doing something wrong, but can’t find what and how to avoid this. Thanks for your help !

SOLUTION :

Finally, it appears that the not spinning ProgressDialog was because I was using the same instance of ProgressDialog and

showDialog(DIALOG_LOADING_ID); 
//doInBackground
dismissDialog(DIALOG_LOADING_ID);

used with causes problem, I changed to

removeDialog(DIALOG_LOADING_ID)

and now it’s working fine.

Thanks All, and hope it can help someone someday !

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T20:09:09+00:00Added an answer on May 26, 2026 at 8:09 pm

    You don’t need to create another task , just instead of doing the search stuff via another activity.

    all you need to do is to put you search cod ein doInbackGround() of search task. e.g

    @Override
    protected Void doInBackground(Void... params) {
    
        global.getDataManager().doSearch();
        return null;
    }
    

    also use class level variable to get search result to store true/false

    @Override
            protected void onPostExecute(Void ret){
    
                // Set you result here
                setIs_loading(my_searh_result);
    
                try {dismissDialog(DIALOG_LOADING_ID);} catch (Exception e){};
    
                if ( searchManager.errorOccurred() ){
                    //Error
                } else {
                    //No Error
    
                }   
            }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an activity that contains several user editable items (an EditText field, RatingBar,
I have an activity with two buttons, start and stop. If the user press
My activity have several static bitmap arrays,but sometimes those static bitmap is gone when
I have an activity that starts on demand of the user. The user can
I have an activity that starts with an AsyncTask to check the connection to
I have Activity A which calls B, at which point let's say the user
I have Activity with ListView and buttons - clear all and OK. On button
I have Activity A with android:launchMode=singleTop in the manifest. If I go to Activity
I have Activity with ListView inside it and in the onCreate method of the
in my app i have activity with XML layout, i want to build an

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.