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

  • Home
  • SEARCH
  • 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 8789175
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T22:19:46+00:00 2026-06-13T22:19:46+00:00

In my app I performing loading data from web and then displaying it to

  • 0

In my app I performing loading data from web and then displaying it to user. Before loading data app shows progress dialog. I have problem if user locks phone in the middle of loading operation, or server is overloaded and can’t respond in time my application freezes, because it doesn’t dismiss progress dialog, or in some cases it crashes because lack on needed data.

If some error happened while loading data I want show some dialog to user to let him know about error and ask him should application repeat last request. I tried to use AlertDialog for it, but I haven’t succeed.

Here is code of one activity (There is no progress dialog here, but it demonstrates how I loading data):

    @EActivity(R.layout.layout_splash)
    @RoboGuice
    public class SplashScreenActivity extends Activity {

    @Inject
    private AvtopoiskParserImpl parser;

    @Bean
    BrandsAndRegionsHolder brandsAndRegionsHolder;

    @ViewById(R.id.splash_progress)
    ProgressBar progressBar;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        loadData();
    }

    @Background
    protected void loadData() {
        publishProgress(10);
        LinkedHashMap<String, Integer> brands = null;
        try {
            brands = parser.getBrands();
        } catch (IOException e) {
            Log.e(e.getMessage());
        }
        publishProgress(50);

        LinkedHashMap<String, Integer> regions = null;
        try {
            regions = parser.getRegions();
        } catch (IOException e) {
            Log.e(e.getMessage());
        }

        publishProgress(70);
        populateData(brands, regions);
    }

    @UiThread
    protected void populateData(LinkedHashMap<String, Integer> brands, LinkedHashMap<String, Integer> regions) {
        Intent intent = new Intent(SplashScreenActivity.this, SearchActivity_.class);
        brandsAndRegionsHolder.brandsMap = brands;
        brandsAndRegionsHolder.regionsMap = regions;
        publishProgress(100);
        startActivity(intent);
        finish();
    }

    @UiThread
    void publishProgress(int progress) {
        progressBar.setProgress(progress);
    }

}

parser.getBrands() and parser.getRegions() are loading data from the web.

I want to do something like this:

    boolean repeatRequest = true;
    while (repeatRequest) {
        try {
            brands = parser.getBrands();
            repeatRequest = false;
        } catch (IOException e) {
            Log.e(e.getMessage());
            repeatRequest = showErrorDialog();
        }
    }

But I didn’t manage to do so because this code executes in background thread, but dialog should be shown in UI thread.
I believe that it should be standard approach of doing so, but didn’t manage to find it.
Any ides how can I implement this?

  • 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-06-13T22:19:47+00:00Added an answer on June 13, 2026 at 10:19 pm

    The best way is to use AsyncTask.

    private class LoadDataTask extends AsyncTask<Void, Integer, Object> {
        private ProgressDialog mProgress;
    
        protected Object doInBackground(Void... params) {
            // This method runs in background
            Object result = null;
            try {
                result = parser.parse();
            } catch (Exception e) {
                result = e.getMessage();
            }
            return result;
        }
    
        protected void onProgressUpdate(Integer... progress) {
            // This method runs in UI thread
            mProgress.setProgress(progress[0]);
        }
    
        protected void onPreExecute() {
            // This method runs in UI thread
            mProgress = new ProgressDialog(context);
            mProgress.show();
        }
    
        protected void onPostExecute(Object result) {
            // This method runs in UI thread
            mProgress.dismiss();
    
            if (result instance of String) {
                // Here you can launch AlertDialog with error message and proposal to retry
                showErrorDialog((String) result);
            } else {
                populateData(result);
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I followed the instructions here Problem performing Ajax call from ASP.NET MVC2 app ,
A WPF app has an operation of loading a user control from a separate
I am performing load testing on my web-app behind the AWS ELB. I have
We are performing some JMeter tests on a JBoss 4.0.5 deployed web app. We
I have my php app working fine, performing some other Graph API functions. However,
I have a Rails app that is storing some user information in a cookie,
We have a webapp performing questionnaire like scans. Entrance point is /app , which
Does in Backbone.Router exists the events both before and after performing routing? My app
As described in the README for facebook-ios-sdk, my app calls Facebook#authorize:delegate: before performing any
I have a problem with my app. I really need to kill it when

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.