0

I have a problem with my app android. I new in this, and i'm learning. I have 2 activities, first call the second activity and in this activity i add string, and i want see this new string in the first activity, I try with this code

protected void onStart() {
    Bundle bundle = getIntent().getExtras();
    paises.add(bundle.getString("Pais"));
    Log.i("pais", bundle.getString("Pais"));
    habitantes.add(bundle.getString("Habitantes"));

    super.onStart();
}

I try with OnCreate, OnResume and my app close, anyone can help me?

In the second activity I put this code

Intent i = new Intent(this, MainActivity.class);
i.putExtra("Pais", pa);
i.putExtra("Habitantes", ha);

EDIT: Is a simple app, in the first activity i have a arrayList, and i want in another activity add to this arrayLista a string, but when i turn to the first activity the arraylist don't update :S

sdelcueto
  • 43
  • 7

3 Answers3

1

Try this:

Intent i = new Intent(this, MainActivity.class);
Bundle args = new Bundle();
args.putString("Pais", pa);
args.putString("Habitantes", ha);
i.putExtras(args);
Bene
  • 724
  • 8
  • 20
1

You have to call super.onStart() first thing.

void onStart(Bundle savedState) {
   super.onStart(savedState);
   // your code here .....
}

same for onResume and onCreate

Alexander Kulyakhtin
  • 47,782
  • 38
  • 107
  • 158
0

It works, ty Alex and Bene, the right form is a mix with you ^^

The first activity onCreate

 if (getIntent().getExtras() != null){
        Bundle bundle = getIntent().getExtras();
        paises.add(bundle.getString("Pais"));
        habitantes.add(bundle.getString("Habitantes"));
    }

The second activity

Intent i = new Intent(this, MainActivity.class);
Bundle args = new Bundle();
args.putString("Pais", pa);
args.putString("Habitantes", ha);
i.putExtras(args);
startActivity(i)
sdelcueto
  • 43
  • 7