(SOLVED) Problem with Progress Dialog

Put your problem here if it does not fit any of the other categories.

(SOLVED) Problem with Progress Dialog

Postby KrLx_roller » Sun Sep 18, 2011 1:40 pm

Hi!

I want to use a Progress Dialog shown while the app is makin an HTTP request. Here's the code I'm using for the progress dialog:

Code: Select all
final ProgressDialog pd = ProgressDialog.show(this, "Title", "Message", true, false);
new Thread(new Runnable()
{
     public void run()
     {
          postLoginData();
          pd.dismiss();
     }
}).start();


And here's the code of the postLoginData();

Code: Select all
public void postLoginData() {
        HttpClient httpclient = new DefaultHttpClient();
       
        HttpPost httppost = new HttpPost("http://mywebpage.com/login.php");

        try {
           EditText uname = (EditText)findViewById(R.id.user);
           String name = uname.getText().toString();

           EditText pword = (EditText)findViewById(R.id.pass);
           String password = pword.getText().toString();
           
            List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
            nameValuePairs.add(new BasicNameValuePair("nick", name));
            nameValuePairs.add(new BasicNameValuePair("password", password));
            httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));

            Log.w("SENCIDE", "Execute HTTP Post Request");
            HttpResponse response = httpclient.execute(httppost);
           
            String str = inputStreamToString(response.getEntity().getContent()).toString();
           
            if(str.toString().trim().equalsIgnoreCase("true"))
            {
               Intent intent = new Intent(Login.this, Example.class);
              startActivity(intent);
              finish();
            }
            else
            {
                result.setText("User and/or password incorrect");
            }



When the user and password are CORRECT, is works great: I hit the button, the progress dialog is shown, and when the request is finished, the progress dialog disappear and the new activity appear. But when the login is wrong, there's a FC. When I change this:

Code: Select all
else
            {
                result.setText("User and/or password incorrect");
            }


for an intent, it works great. Can someone help me? Thank you in advantage!
Last edited by KrLx_roller on Sun Sep 18, 2011 9:46 pm, edited 1 time in total.
KrLx_roller
Freshman
Freshman
 
Posts: 9
Joined: Sun Sep 18, 2011 1:26 pm

Top

Re: Problem with Progress Dialog

Postby Dockland » Sun Sep 18, 2011 3:26 pm

There is no way to access GUI thread UI objects from worker thread. Use methods described in devguide.
Dockland
Developer
Developer
 
Posts: 37
Joined: Wed Jul 27, 2011 12:29 pm

Re: Problem with Progress Dialog

Postby KrLx_roller » Sun Sep 18, 2011 7:17 pm

I don't know what you are referred to... Can you give me a link? I've been seraching for information, and I find a lot of stuff, but I don't know how to implement it to my code :/ Thank you!
KrLx_roller
Freshman
Freshman
 
Posts: 9
Joined: Sun Sep 18, 2011 1:26 pm

Re: Problem with Progress Dialog

Postby KrLx_roller » Sun Sep 18, 2011 9:46 pm

I've solved my problem with:

Code: Select all
result.post(new Runnable(){
    public void run() {
          result.setText("Usuario y/o contraseña erróneos");
    }
});


Thank you!
KrLx_roller
Freshman
Freshman
 
Posts: 9
Joined: Sun Sep 18, 2011 1:26 pm

Re: (SOLVED) Problem with Progress Dialog

Postby Dockland » Mon Sep 19, 2011 7:07 am

Dockland
Developer
Developer
 
Posts: 37
Joined: Wed Jul 27, 2011 12:29 pm

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: Google [Bot] and 18 guests