How do I get a variable in another activity?

后端 未结 3 1191
难免孤独
难免孤独 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:57

    If you didn't want to use a global variable you could always create a method in your activity to return your string.

    public static String getMyString(){
        return item;
    }
    

    Then in your current activity you could call:

    String myValue = LoginScreen.getMyString();
    

提交回复
热议问题