2010-06-10 2 views
0

ci-dessous est le code d'un formulaire d'inscription, lorsque nous CLIQUEZ deuxième fois pour soumettre les détails, le l'application s'effondre et les hags affichent simplement le dialog_thread .... Lors de l'exécution de la première fois il rum parfaitement .............. Le code de dialog_thread est donné après onClick() .... Merci de nous aider moi, comment se débarrasser de ce problème et de laisser l'application bon déroulement .....L'application se bloque ou se bloque lors de la soumission des données dans le formulaire d'inscription, la deuxième fois ... Première fois qu'il fonctionne parfaitement

PLZ HELP mE FAST ...

onClick public void (Voir arg0) {// TODO Auto- méthode générée talon

alert_dialog ad=new alert_dialog(); 

    try 
    { 
     if(arg0==signup) 
     { 
      if(password.getText().toString().equals(confirm_password.getText().toString())) 
      { 
       //**** Start loading dialog thread 

       dt=new dialog_thread(this); 
       Log.i("dialog thread","Object created"); 

       dt.start(); 
       Log.i("dialog thread","thread started"); 

       String message=null; 
       Integer success=null; 

       //************ Encrypt the password 
       String encrypt_password=new md5(password.getText().toString()).getEncryped(); 

       //************* create name value pair 
       ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(); 

       nameValuePairs.add(new BasicNameValuePair("username",username.getText().toString())); 
       nameValuePairs.add(new BasicNameValuePair("password",encrypt_password)); 
       nameValuePairs.add(new BasicNameValuePair("email",email.getText().toString())); 
       nameValuePairs.add(new BasicNameValuePair("func","signup")); 
       nameValuePairs.add(new BasicNameValuePair("user_type",s.getSelectedItem().toString())); 

       DBConnect db=new DBConnect(); 
       String result=db.fetch_data(nameValuePairs); 
       //******** Toast.makeText(this, result, Toast.LENGTH_LONG).show(); 

       //************* Parse JSONArray returned 

       JSONArray jArray = new JSONArray(result); 

       for(int i=0;i<jArray.length();i++) 
       { 
        JSONObject json_data = jArray.getJSONObject(i);     
        success=json_data.getInt("success");      
        message=json_data.getString("message");     
       } 

       //************ Stop loading dialog thread 
       dt.stop_execution(); 

       if(success==1) 
        Toast.makeText(this,"You have sucessfully signed up", Toast.LENGTH_LONG).show(); 
       else 
        {      
         ad.alertbox(this, "", message); 
        } 
      } 
      else 
       ad.alertbox(this, "", "Error : Please enter the same password"); 
     } 
    }catch(Exception e) 
    { 
     Log.i("Exception in signup",e.toString()); 
    } 
} 

}

(CE CODE EST DANS UN FICHIER DIFFERENT)

classe dialog_thread extends Thread {

ProgressDialog pd; 
Context c; 
String title="Working ..."; 
String msg="Please Wait ..."; 

dialog_thread(Context cont) 
{ 
    c=cont; 
} 

dialog_thread(Context cont,String title,String msg) 
{ 
    c=cont; 
    this.title=title; 
    this.msg=msg; 
} 

public void run() 
{ 
    // TODO Auto-generated method stub 
    try 
    { 
     Looper.prepare(); 
     pd = ProgressDialog.show(c, this.title, this.msg, true, false); 
     Handler handler = new Handler() 
           {    
            public void handleMessage(Message msg) 
             { 
              //pd.dismiss();           
              Log.i("Handler","Inside handler"); 
              Log.i("dissmissing thread",msg.toString()); 
             }    
           }; 
     handler.sendEmptyMessage(0); 
     Log.i("TRy block","Executed"); 
     Looper.loop(); 
    } 
    catch(Exception e) 
    { 
     Log.i("Exception in dialog thread",e.toString()); 
    } 
//************************ Run ends here  
} 

public void stop_execution() 
{ 
    pd.dismiss(); 
    this.stop(); 
} 

// *********** ***** La classe se termine ici
}

Répondre

0

En Java, vous ne pouvez pas redémarrer un tr un d. Dans votre onClick recréer le fil. Simplement appeler à nouveau son constructeur fonctionnera. Cela fonctionne la première fois car le thread n'a pas encore été arrêté. Après la première modification lorsque vous revenez de la gestion de l'action, le thread est arrêté et la seconde fois, il se bloque car vous essayez de redémarrer un thread arrêté.

Espérons que ça aide.

Questions connexes