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

后端 未结 4 502
南笙
南笙 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:37

    Actually its not possible to go from 1st activity to 3rd directly...

    You must have to follow the activity stack..

    So if you want the data to be passed from 1st to 3rd follow by

    1st -> 2nd -> 3rd

    with the use of intent suggested by @Lalit Poptani

    0 讨论(0)
  • 2021-01-24 12:42

    You may keep them as static objects and retrieve as Myclass.myObject. But what you really want is impossible.

    0 讨论(0)
  • 2021-01-24 12:54

    You can use a database, SharedPreferences, Application, Static Methods and more for share data between Activitys. Look here

    0 讨论(0)
  • 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");
      
    0 讨论(0)
提交回复
热议问题