0

I have a class called ConectarAsyncTask and I would like to connect my app in the MainActivity and keep it for all the activities, can I do it like being a secondary thread class?

This is my connection code:

public class ConectarAsyncTask extends AsyncTask<String, Void, String> {

Connection conn;
String resultadoConexion;

@Override
protected String doInBackground(String... urls) {

    try {
        Class.forName("com.mysql.jdbc.Driver");
        conn = DriverManager.getConnection("jdbc:mysql://1111111/xxxxxxxxxxxxxxxxxxxxxx");
        System.out.println("CONEXION AsyncTask:   "+conn );
        Log.i("Exito", "Conexion a la base de datos realizada con exito");
        resultadoConexion = "Conectado";
    }

    catch (Exception e){
        resultadoConexion = "Error al conectar";
        Log.i("ErrorBBDD", "Error: " + e.getMessage());
        e.printStackTrace();
    }
    return resultadoConexion;
}

public Connection getConn() {
    return conn;
}

public void setConn(Connection conn) {
    this.conn = conn;
}
Javier
  • 1
  • 1
  • Doesn't answer your question but please read: http://stackoverflow.com/questions/15853367/jdbc-vs-web-service-for-android – Morrison Chang Apr 07 '15 at 17:43
  • I have read it and seems to be very good but i´m only trying different things and I need to do it by this way – Javier Apr 07 '15 at 17:59

0 Answers0