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

前端 未结 4 1401
一整个雨季
一整个雨季 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条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-03 16:54

    A sample from my project. We have to use Bundle to get the data.

    Use the code in the from/first activity yo set the data. You can set all kind of data types including arrays.

    Intent i = new Intent(this, LanguageSetting.class);
    i.putExtra("From", 1);
    startActivity(i);
    

    How to retrive the data, write the below code in the new/second activity.

    Intent myIntent = getIntent();
    Bundle b = myIntent.getExtras();
    intCameFrom = b.getInt("From");
    

提交回复
热议问题