Pass data between Activtiys using the database (Sqlite)?

0

I have a question about how to pass information between activitys using the database, since I have seen many tutorials on how to do it, but they always do it with a typed key and I use a autoincrementable and I do not know how to use it to pass the data and keep the context on that same table while using the application.

Here I leave the code of when I register something and move on to the other activity:

Intent irTrabajo = new Intent (dialog.getContext (), menu_trabajo_Activity.class);

            //acceso a la base de datos
            ConexionBaseDatos conexion = new ConexionBaseDatos(dialog.getContext(), "bd_uno", null, 1);

            final String Nombre = editNombre.getText().toString();
            final String Tipo = ediTipo.getText().toString();
            //abro el modo escritura
            SQLiteDatabase db = conexion.getWritableDatabase();

            //metodo para agregar los valores
            ContentValues values = new ContentValues();
            values.put(ConstantesDatos.Nombre, Nombre);
            values.put(ConstantesDatos.Tipo, Tipo);

            //insertar valores a la base de datos
            long EnvioLibro = db.insert(ConstantesDatos.Tabla_Nombres, null, values);
            Toast.makeText(getBaseContext(), "Se agrego con exito", Toast.LENGTH_SHORT).show();

            //cerrar la base de datos
            db.close();
    
asked by 05.05.2018 в 22:56
source

1 answer

0

Create a class that is called utilities or as you like, within it creates the variables you want to use during the execution of the application, for example:

class Utilidades{
 public static String Nombre;
 public static String Tipo;
}

where you create the ContentValues to assign the variables for the insertion in the database add:

Utilidades.Nombre=Nombre;
Utilidades.Tipo=Tipo;

and in the activity or where you want to recover the data you call the class that contain the static varials.

Log.i("LOG",Utilidades.Nombre);

This is recommended only when you use a few variables because if there are several variables, you will use more mobile resources

    
answered by 06.05.2018 / 05:57
source