In Android: How do I get variables/data from one screen to another?

前端 未结 4 1400
一整个雨季
一整个雨季 2020-12-03 16:05

In android: I\'m trying to take data from one activity/screen to another.

Let\'s say I\'m adding two numbers. I layout my first screen (xml) with 2 EditText views, a

4条回答
  •  臣服心动
    2020-12-03 16:42

    First Activity

    Intent myIntent = new Intent();
    myIntent.putExtra("key", "value");
    startActivity(myIntent); 
    

    New Activity

    Intent myIntent = getIntent(); // this is just for example purpose
    myIntent.getExtra("key");
    

    Check out the different types you can use on the Android Dev Site

    Note: If you're looking for a way of sharing an object/data globally then you could extend the Application class. Check out How to declare global variables in Android? (answer by Soonil)

提交回复
热议问题