Send variable between classes via Intent

I'm having trouble using Intent to navigate screens. I want to send a variable and use it in another class.

I use a method, the method accepts a variable, but I don’t know how to send it with the intention to a new screen, which will use it to perform some actions.

The main class calls the method:

private void pantallaDetalles(final int identificador)
{
     startActivityForResult(new Intent(this,MostrarDetalles.class),REQST_CODE);
}

MostrarDetalles.class is * .java that will take a variable. I start like this:

public class MostrarDetalles extends Activity {

    SQLiteDatabase db;

    public void onCreate(Bundle savedInstanceState)
        {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.detalles);


         //more code...


         Cursor c = db.rawQuery("SELECT * FROM table WHERE _id="+ identificador, null);

        }

You saw? I talk about it. I do not know how to send the variable "identificador" from the main class to the second class through Intent.

Can you help me? Thank you so much for the advice.

JMasia.

+5
3

.

Intent i = new Intent(...);
i.putExtra("name_of_extra", myObject);

on onCreate:

getIntent.getIntExtra("name_of_extra", -1);
+12

1:

Intent i=new Intent("com.suatatan.app.Result");
                i.putExtra("VAR_RESULT", "Added !");
                startActivity(i);

2: ():

TextView tv_sonuc = (TextView) findViewById(R.id.tv_sonuc);

Bundle bundle = getIntent().getExtras();

String var_from_prev_intent = bundle.getString("VAR_RESULT");
tv_sonuc.setText(var_from_prev_intent);
+6

You can use Intent.putExtra()to bind the data you want to send with intent.

0
source

All Articles