Avoid losing data from one activity when opening another

0

I have an activity where they have images and text. The problem is that when you open the next one, you lose the information.

Intent i = new Intent(getApplicationContext(), Numeros_App.class);
startActivity(i);

How can I keep the information of images and text that is found.

i.putExtra

I guess it's not an option for this.

I need to return to this activity that contains that information without losing the data.

    
asked by DoubleM 03.01.2018 в 06:34
source

1 answer

0

Let's say you want to pass the contents of a string with a putExtra from one activity to another, for example, I have an intent that goes from one class to another, and when I take the UserEdit class a putExtra with the tag " Name "and after the comma the content that must carry Name, which is of type string

adapter.getItem(position).getNombre() 

this line returns a String with a name and stores it with the Tag "Name"

    Intent intent = new Intent(MainActivity.this, UserEdit.class);                    
                          intent.putExtra("Nombre",adapter.getItem(position).getNombre());

Now, to get this value in my other activity

 Intent iin= getIntent();
         Bundle b = iin.getExtras();

        if(b!=null)
        {
            String n =(String) b.get("Nombre");
            Log.e("El nombre es: ",""+n);
}else{
Toast.makeText(this, "No se pudo traer el Extra", Toast.LENGTH_SHORT).show();
}

I just create a getIntent, and a Bundle which gets the extras, check that is different from null to confirm that it comes with some content, and then I put b.get ("Name") and get the Name from my other activity

This is how it works to get data from one activity to another

    
answered by 04.01.2018 в 13:30