Note that there are some explanatory texts on larger screens.

plurals
  1. POLaunch second Intent & View from Main Activity and display ProgressDialog with Thread
    text
    copied!<p>I'm having some problems displaying a ProgressDialog. I have a method that scrapes information from a website, and I want to show the user some kind of "Loading" window instead of the app just looking like it is hanging for a second or two when it is working.</p> <p>Everything works fine when I don't implement a ProgressDialog &amp; Thread, but as soon as I try to implement a Thread to do the heavy lifting, the AboutMe View window is empty.</p> <p>I have a MainActivity with a TextView that registers a OnClickListener.</p> <p>A Click on the TextView does a:</p> <pre><code> startActivity(new Intent(getBaseContext(), AboutMe.class)); </code></pre> <p>This is most of the AboutMe.class Activity:</p> <pre><code>public class AboutMe extends Activity { private ProgressDialog aboutMeProgressDialog; private String htmlAboutMe = ""; @Override protected void onCreate(Bundle savedInstanceState) { getAboutMe(); // Get information from Internet super.onCreate(savedInstanceState); requestWindowFeature(Window.FEATURE_NO_TITLE); getWindow().setFeatureDrawableResource(Window.FEATURE_NO_TITLE, android.R.drawable.ic_dialog_alert); setContentView(R.layout.abutme); TextView tvAbout = (TextView) findViewById(R.id.aboutMe); tvAbout.setText(Html.fromHtml(htmlAboutMe)); } private void getAboutMe() { try { aboutMeProgressDialog = ProgressDialog.show(AboutMe.this, "", "Loading"); new Thread() { @Override public void run() { try { /** Code to scape webpage **/ } catch (Exception exp) { exp.printStackTrace(); } handler.sendEmptyMessage(0); } }.start(); } catch (Exception ex) { ex.printStackTrace(); } } private final Handler handler = new Handler() { @Override public void handleMessage(final Message msg) { aboutMeProgressDialog.dismiss(); } }; </code></pre> <p>I'm clearly missing out on something trivial, but I've tried to Google just about everything I can think of, but still can't get a Thread together with ProgressDialog to work for me.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload