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 3490000
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T11:27:47+00:00 2026-05-18T11:27:47+00:00

I’m having serious problems when showing a ProgressDialog while a service is getting ready…

  • 0

I’m having serious problems when showing a ProgressDialog while a service is getting ready… The service takes time to get ready as it’s a bit heavy, so I want to show the ProgressDialog meanwhile it’s started.

The thing is that it shows the ProgressDialog right before the next activity starts… I really don’t find what it is…

package org.pfc;

import android.app.Activity;
import android.app.ProgressDialog;
import android.content.BroadcastReceiver;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.ServiceConnection;
import android.os.Bundle;
import android.os.IBinder;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;


public class ConnectActivity extends Activity {

    // FIELDS------------------------------------------------------------------

    protected LocalService mSmeppService;
    private ProgressDialog progressDialog;

    private Thread tt;

    private ServiceConnection mConnection = new ServiceConnection() {
        public void onServiceConnected(ComponentName className, IBinder service) {
            // Gets the object to interact with the service
            mSmeppService = ((LocalService.LocalBinder) service).getService();
        }

        public void onServiceDisconnected(ComponentName className) {
            // This is called when the connection with the service has been
            // unexpectedly disconnected -- that is, its process crashed.
            // Because it is running in our same process, we should never
            // see this happen.
            mSmeppService = null;
        }
    };

    // For getting confirmation from the service
    private BroadcastReceiver serviceReceiver = new BroadcastReceiver() {

        @Override
        public void onReceive(Context context, Intent intent) {
            Log.i(TAG, "receiver onReceive...");

            if (progressDialog.isShowing())
                progressDialog.dismiss();

            // Change activity
            Intent groupsActivityIntent = new Intent(ConnectActivity.this,
                    GroupsActivity.class);
            startActivity(groupsActivityIntent);
        }
    };

    // METHODS ----------------------------------------------------------------

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        if (LocalService.isRunning) {
            // TODO start ListActivity
            Log.i(TAG, "Starting GroupsScreen");

            Intent i = new Intent(ConnectActivity.this, GroupsActivity.class);
            startActivity(i);
        } else {

            setContentView(R.layout.connect_screen);

            // Add listener to the button
            Button buttonConnect = (Button) findViewById(R.id.button_connect);
            buttonConnect.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    processThread();
                }
            });
        }
    }


    // PRIVATE METHODS --------------------------------------------------------

    private void processThread() {

        progressDialog = ProgressDialog.show(ConnectActivity.this, "",
                "Loading. Please wait...", true, false);

        tt = new Thread() {
            public void run() {

                // Register broadcastReceiver to know when the service finished
                // its creation
                ConnectActivity.this.registerReceiver(serviceReceiver,
                        new IntentFilter(Intent.ACTION_VIEW));

                // Starts the service
                startService(new Intent(ConnectActivity.this,
                        LocalService.class));

                Log.i(TAG, "Receiver registered...");
            }
        };
        tt.start();
    }
}

The service executes by the end of the onStart method this:

// Send broadcast so activities take it
Intent i = new Intent(Intent.ACTION_VIEW);
    sendOrderedBroadcast(i, null);

So the onReceive method runs and we go to the next activity

  • 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-18T11:27:48+00:00Added an answer on May 18, 2026 at 11:27 am

    The problem is that you are not running ProgressDialog in a UI thread.

    Add a handler that will handle messages in your UI thread.

    private static final int UPDATE_STARTED = 0;
    private static final int UPDATE_FINISHED = 1;
    
    private Handler handler = new Handler(){
      @Override public void handleMessage(Message msg) {
        switch (msg.what) {
         case UPDATE_STARTED:
           progressDialog = ProgressDialog.show(ConnectActivity.this, "",
                "Loading. Please wait...", true, false);                
         break;  
         case UPDATE_FINISHED:
           if(progressDialog.isShowing()){
             progressDialog.dismiss();    
           }            
         break;
        }
      }
    };
    
    
    private void processThread() {
      Message m = new Message();
      m.what = UPDATE_STARTED;
      handler.sendMessage(m);
    
      //Your working code
    
      m = new Message();
      m.what = UPDATE_FINISHED;
      handler.sendMessage(m);
    }
    

    good luck!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
Seemingly simple, but I cannot find anything relevant on the web. What is the
Does anyone know how can I replace this 2 symbol below from the string
this is what i have right now Drawing an RSS feed into the php,
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but

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.