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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T06:22:30+00:00 2026-06-01T06:22:30+00:00

I have read some threads regarding this and I did already take steps to

  • 0

I have read some threads regarding this and I did already take steps to resolve it.
I am using a handler (so that I don’t update the UI on a separate thread) and so far I can’t understand why this is still happening.

public class MyApp extends Activity implements OnClickListener, Runnable {

    private ViewSwitcher switcher;
    private static final int REFRESH_SCREEN = 1;
    private boolean isValid = false;
    private ProgressDialog dialog;
    private TextView errorMessage;      

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        Button button = (Button)findViewById(R.id.button1);
        button.setOnClickListener(this);

        TextView errorMessage = (TextView)findViewById(R.id.txtErrorMessage);
        errorMessage.setVisibility(View.GONE);

        switcher = (ViewSwitcher) findViewById(R.id.profileSwitcher);
    }

    public void onClick(View v)  
    {
        isValid = false;
        dialog = ProgressDialog.show(ConcentraApp.this, "", "Loading. Please wait...", true);

        Thread thread = new Thread(this);
        thread.start();
    }

    public void run() {
        String username = ((TextView)findViewById(R.id.txtUsername)).getText().toString();
        String password = ((TextView)findViewById(R.id.txtPassword)).getText().toString();
        errorMessage = (TextView)findViewById(R.id.txtErrorMessage);
        errorMessage.setVisibility(View.GONE);

        /* ... contact web service and get response ..*/

        try {
            /* get result from web service */
            isValid = Boolean.parseBoolean(result);
            if(isValid)
            {
                handler.sendEmptyMessage(1);                
            }
            else
            {
                handler.sendEmptyMessage(0);    
            }

        } catch (Exception e) {
            handler.sendEmptyMessage(2);
            isValid = false;        
        }                                             
    }

    private Handler handler = new Handler() {
         @Override
         public void handleMessage(Message msg) {
             if(msg.what == 1)
             {
                 errorMessage.setVisibility(View.VISIBLE);
                 errorMessage.setText("Correct login");
                 switcher.showNext();
             }
             else if(msg.what == 0)
             {
                 errorMessage.setVisibility(View.VISIBLE);
                 errorMessage.setText("Invalid login");
             }
             else
             {
                 errorMessage.setVisibility(View.VISIBLE);
                 errorMessage.setText("Internet error");
             }
             dialog.dismiss();
         }
        };
}

I am very new to this so I wouldn’t be surprised if I’m missing something obvious.
It works fine without the thread, but then the process dialog doesn’t show.

Many thanks in advance

  • 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-01T06:22:31+00:00Added an answer on June 1, 2026 at 6:22 am

    You cannot call this:

    errorMessage.setVisibility(View.GONE);
    

    From a background thread. You should do it via handler as well.

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

Sidebar

Related Questions

I have read some posts about this topic and the answers are comet, reverse
I have read some articles on POCO in the enttity framework but still don't
I have read in some of the ClickOnce posts that ClickOnce does not allow
I have read from some article that say's Apple doesn't approve the application which
I just got Delphi 2009 and have previously read some articles about modifications that
I am new to ASP.net MVC architecture. I have read in some articles that
I have a huge array that has to be read by different threads in
I have some questions regarding read-write locks in POSIX Pthreads on a *nix system,
I have read some posts on here about not mixing parameters when passing into
I have just switched from svn to mercurial and have read some tutorials about

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.