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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T11:11:07+00:00 2026-06-13T11:11:07+00:00

I can’t seem to get this to work, after a progressDialog finish display how

  • 0

I can’t seem to get this to work, after a progressDialog finish display how can I display an alert dialog?

here’some relevant code:

progressDialog = ProgressDialog.show(MainActivity.this, "", "Loading...");

        new Thread() {
            public void run() {
                try{
                    initializer();
                } catch (Exception e) {
                    Log.e("tag", e.getMessage());
                }
                progressDialog.dismiss();
                SharedPreferences welcome_pref = PreferenceManager.getDefaultSharedPreferences(MainActivity.this);
                welcome = welcome_pref.getString("getwelcome", "null");

                if (welcome.equals("no")) {

                }else{
                    AlertDialog welcome = new AlertDialog.Builder(MainActivity.this).show();
                    welcome.setContentView(R.layout.welcome);
                    welcome_pref = PreferenceManager.getDefaultSharedPreferences(MainActivity.this);
                    SharedPreferences.Editor welc = welcome_pref.edit();
                    welc.putString("getwelcome", "no");
                    welc.commit();
                }
            }
        }.start();
    }

    private void initializer() {
        startMoving = (ImageView) findViewById(R.id.imMove);
        aboutApp = (ImageView) findViewById(R.id.imAbout);
        devSite = (ImageView) findViewById(R.id.imDevSite);
        movingTips = (ImageView) findViewById(R.id.imTips);
        rateApp = (ImageView) findViewById(R.id.imRate);

        start = (EditText) findViewById(R.id.etFrom);
        end = (EditText) findViewById(R.id.etTo);

        startMoving.setOnClickListener(this);
        aboutApp.setOnClickListener(this);
        devSite.setOnClickListener(this);
        movingTips.setOnClickListener(this);
        rateApp.setOnClickListener(this);

        tvabout = (TextView) findViewById(R.id.tvabout);
        tvstartmove = (TextView) findViewById(R.id.tvStart);
        tvrate = (TextView) findViewById(R.id.tvRate);
        tvdevelop = (TextView) findViewById(R.id.tvDev);
        tvmovetips = (TextView) findViewById(R.id.tvTips);

        tvabout.setShadowLayer(30, 0, 0, 0xff000000);
        tvstartmove.setShadowLayer(30, 0, 0, 0xff000000);
        tvrate.setShadowLayer(30, 0, 0, 0xff000000);
        tvdevelop.setShadowLayer(30, 0, 0, 0xff000000);
        tvmovetips.setShadowLayer(30, 0, 0, 0xff000000);

        checklistitem();

    }

    private void checklistitem() {
        SharedPreferences createlistitem_pref = PreferenceManager.getDefaultSharedPreferences(MainActivity.this);
        checkitem = createlistitem_pref.getString("getcheck", "null");

        if (checkitem.equals("no")) {

        }else{
            SQLHandler checkitemstat = new SQLHandler(MainActivity.this);
            checkitemstat.open();
            checkitemstat.createList();
            checkitemstat.close();
            SharedPreferences setitem_pref = PreferenceManager.getDefaultSharedPreferences(MainActivity.this);
            SharedPreferences.Editor setcheck = setitem_pref.edit();
            setcheck.putString("getcheck", "no");
            setcheck.commit();
        }
    }
}

I’m getting an error saying Can't create handler inside thread that has not called Looper.prepare() I know whats causing this error but i don’t know how to fix this.

This line of code is the one that’s causing this.

                progressDialog.dismiss();
                SharedPreferences welcome_pref = PreferenceManager.getDefaultSharedPreferences(MainActivity.this);
                welcome = welcome_pref.getString("getwelcome", "null");

                if (welcome.equals("no")) {

                }else{
                    AlertDialog welcome = new AlertDialog.Builder(MainActivity.this).show();
                    welcome.setContentView(R.layout.welcome);
                    welcome_pref = PreferenceManager.getDefaultSharedPreferences(MainActivity.this);
                    SharedPreferences.Editor welc = welcome_pref.edit();
                    welc.putString("getwelcome", "no");
                    welc.commit();
                }
  • 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-13T11:11:08+00:00Added an answer on June 13, 2026 at 11:11 am

    Add your Alert Dialog show code within runonUiThread,

    this.runOnUiThread(new Runnable() {
    
                    public void run() {
                        // TODO Auto-generated method stub
    
                    }
                });
    

    Something like this,

    }else{
    
     MainActivity.this.runOnUiThread(new Runnable() {
    
                    public void run() {
                          AlertDialog welcome = new AlertDialog.Builder(MainActivity.this).show();
                welcome.setContentView(R.layout.welcome);
                    }
                });
    
    
                        welcome_pref = PreferenceManager.getDefaultSharedPreferences(MainActivity.this);
                        SharedPreferences.Editor welc = welcome_pref.edit();
                        welc.putString("getwelcome", "no");
                        welc.commit();
                    }
    

    As one of the answer suggested here says, you can’t update your UI from a worker thread. You got to be in UI thread when you update any UI.

    So you need to use handlers or runonUiThread to do this. But since runOnUiThread internally uses handlers it should do help you.

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

Sidebar

Related Questions

Can someone please explain why this doesn't work? MyClass myClass1 = new MyClass(); object
Can anybody shed some light on getDay() in Javascript please. Here datepicker is textbox
Can find why i get this error can someone help? package Android.data; public class
Can anyone help me trying to find out why this doesn't work. The brushes
Can I change the field public virtual ClassOne ClassOne { get; set; } to
Can any one tell, how to get the result of LINQ query contains group
Can we change the default action of the edit selected row button? Here is
Can anyone explain to me why this program: for(float i = -1; i <
Can I run this in a Windows command prompt like I can run it
Can anybody help me? What should be the datatype for this type -07:00:00 of

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.