How do I get a variable in another activity?

后端 未结 3 1216
难免孤独
难免孤独 2020-12-31 12:58

How do I access variable value in another activity. In my example I have a string variable item which value is spinner selected value. How can I access this variable in ano

3条回答
  •  长情又很酷
    2020-12-31 13:52

    You can declare them as static variables and then in your other class you may access them like Activity1.stringName.

    public static String stringName; 
    
    stringName = .. // value from Spinner
    

    Then, in all the other Activities, you can access them as YourMainActivty.stringName.

提交回复
热议问题