how to directly pass value of a variable from 1st activty to 3rd activity using putextra?

后端 未结 4 511
南笙
南笙 2021-01-24 12:09

how to directly pass value of a variable from 1st activity to 3rd activity using putextra?

For example:

I have a variable A in the first screen (first activity)

4条回答
  •  时光取名叫无心
    2021-01-24 12:59

    You can pass any value between any two Activities you want. You just need to do two things:

    • In your FirstActivity:

      Intent intent = new Intent(context, ThirdActivity.class);
      i.putExtra("value_key", value); //valus is a String
      startActivity(intent);
      
    • In your ThirdActivity's onCreate():

      Bundle b = getIntent().getExtras();
      String value = (String) b.getString("value_key");
      

提交回复
热议问题