java - Calling a function with setContentView(R.layout) from another function? -


when call dbconctfun(view v) method through onclick threads , runnable code executing last after executing other code in dbconctfun(view v) method. in console shows:

out of loop   out of loop test#######   multiple class.forname queryexct     queryexct 

my code:

package com.example.loginandroid;  import java.sql.connection; import java.sql.drivermanager; import java.sql.resultset;  import java.sql.sqlexception; import java.sql.statement; import android.os.bundle; import android.app.activity; import android.app.alertdialog; import android.util.log; import android.view.view; import android.widget.edittext; import android.widget.toast; import android.os.looper;  public class mainactivity extends activity{     string username,password;     resultset rs =null;     boolean temcfag=false,temqfag=true;     public static string tag="lifecycle activity";     edittext user,pass;     alertdialog.builder dialog;     @override     protected void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);         setcontentview(r.layout.activity_main);         dialog=new alertdialog.builder(this);         dialog.setneutralbutton("ok", null);           user=(edittext)findviewbyid(r.id.edittext1);         pass=(edittext)findviewbyid(r.id.edittext2);     }      thread  thrd1,thrd2,thrd3;     connection con;     string result ="",queryexct;      public void dbconctfun(view v )  throws sqlexception {          try {             class.forname("com.mysql.jdbc.driver");              log.v("test#######","multiple class.forname");         } catch (classnotfoundexception e) {             e.printstacktrace();         }         thrd1 = new thread(new runnable() {             public void run() {                 while (!thread.interrupted()) {                     try {                         thread.sleep(100);                     } catch (interruptedexception e1) {                     }                     if (con == null) {                         try {                             con = drivermanager.getconnection("jdbc:mysql://111.111.11.11:6666/dyne", "root1", "mysql");                         } catch (sqlexception e) {                             e.printstacktrace();                             con = null;                         }                          if ((thrd2 != null) && (!thrd2.isalive()))                             thrd2.start();                      }                 }              }         });         if ((thrd1 != null) && (!thrd1.isalive())) thrd1.start();          thrd2 = new thread(new runnable() {             public void run() {                 while (!thread.interrupted()) {                      if (con != null) {                         if (temqfag) {                         try {                             statement st = con.createstatement();                             username=user.gettext().tostring().trim();                             password=pass.gettext().tostring().trim();                             queryexct="select *  `user_registration`  `email_id` =  '"+username+"' ,  `password` =  '"+password+"'";                             rs = st.executequery(queryexct);                             log.v("queryexct","queryexct");                             temqfag=false;                         } catch (sqlexception e) {                             e.printstacktrace();                             con = null;                         }                          try {                             log.v("test#######","errorrrrrrrrrrr3");                             if (temqfag) {thread.sleep(10);}                         } catch (interruptedexception e) {                             e.printstacktrace();                         }}                     } else {                         try {                             log.v("test#######","errorrrrrrrrrrr4");                             thread.sleep(300);                         } catch (interruptedexception e) {                             e.printstacktrace();                         }                     }                 }             }          });         log.v("out of loop","out of loop");         if(rs!=null){             if (rs.next()) {                 log.v("test#######","errorrrrrrrrrrr1");                 looper.prepare();                 thread.interrupted();                 setcontentview(r.layout.activity_main1);                 log.v("test#######","errorrrrrrrrrrr1");             }             else{                 log.v("test#######","errorrrrrrrrrrr2");                 thread.interrupted();                 looper.prepare();                  dialog.setmessage("your username , password not valid");                 dialog.show();               }         }         temqfag=true;     } } 

i didn't trying understand if trying change layout using threads won't able because possible on main thread.


Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -