Título: Error con Thread
Publicado por: Baal_30 en 6 Mayo 2016, 21:12 pm
Buenas noches, llevo todo el día devanandome los sesos con acceso a una bbdd desde android, he visto que hay que hacerlo desde un thread, he estado mirando y mirando y he hecho como ponían por ahí, pero me da este error y no tengo ni idea ni logro entenderlo, ¿alguien me echa una mano? :D
05-06 19:05:01.836 2097-2201/com.google.android.googlequicksearchbox:search W/Search.SearchUrlHelper: Auth token not ready, no auth header set. 05-06 19:05:01.852 2718-2718/? E/ActivityThread: Service com.android.email.service.EmailBroadcastProcessorService has leaked ServiceConnection com.android.emailcommon.service.ServiceProxy$ProxyConnection@6623d1f that was originally bound here android.app.ServiceConnectionLeaked: Service com.android.email.service.EmailBroadcastProcessorService has leaked ServiceConnection com.android.emailcommon.service.ServiceProxy$ProxyConnection@6623d1f that was originally bound here
Título: Re: Error con Thread
Publicado por: Baal_30 en 7 Mayo 2016, 14:13 pm
Pongo el código con las dos clases (main y la asynctask) a ver si alguien me puede ayudar, el problema es que en el Toast que muestra despues de ejecutar el hilo, siempre me pone "Vacío". public class MainActivity extends AppCompatActivity { EditText etUsuario; EditText etPass; public static String login = "Vacío"; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); btnEntrar = (Button) findViewById (R. id. btnEntrar); etUsuario = (EditText) findViewById(R.id.etUsuario); etPass = (EditText) findViewById(R.id.etPass); btnEntrar. setOnClickListener(new View. OnClickListener() { @Override public void onClick (View v ) { String usuario = etUsuario. getText(). toString(); String pass = etPass. getText(). toString(); new ConnUsers(usuario, pass).execute(); Toast.makeText(MainActivity.this, login, Toast.LENGTH_SHORT).show(); /*if(login){ Intent intent = new Intent(MainActivity.this, IncidenciasActivity.class); startActivity(intent); Toast.makeText(MainActivity.this, "Acceso es TRUE", Toast.LENGTH_SHORT).show(); } else{ Toast.makeText(MainActivity.this, "Acceso es FALSE", Toast.LENGTH_SHORT).show(); } */ } }); } private class ConnUsers extends AsyncTask <String, String, String >{ private static final String DB_DRIVER = "org.postgresql.Driver"; private static final String url = "jdbc:postgresql://xxx/xxx"; private static final String user = "xxx"; private static final String password = "xxx"; this.usuario = usuario; this.pass = pass; } @Override String acceso = "doInBackground"; try{ Class.forName(DB_DRIVER); ResultSet rs = st. executeQuery("SELECT * FROM usuarios WHERE usuario = '" + usuario +"'"); if(rs.next()!=false){ if(Funciones.md5(pass).equalsIgnoreCase(rs.getString("password"))){ int id = rs.getInt("id"); acceso = "Todo correcto"; } else{ //Toast.makeText(context, "Password incorrecto", Toast.LENGTH_LONG).show(); acceso = "Falla la pass"; } } else{ //Toast.makeText(context, "Usuario incorrecto", Toast.LENGTH_LONG).show(); acceso = "Falla el usuario"; } rs.close(); st.close(); connection.close(); cancel(true); e.printStackTrace(); e.printStackTrace(); e.printStackTrace(); } return acceso; } @Override protected void onPostExecute (String s ) { MainActivity.login = s; } @Override protected void onCancelled() { } } }
Gracias de antemano.
|