我希望如果有一种方式来传递来自活性1(技术)2个数据变量活性2(用户),其中活性1给出2个当前的默认值(x 1和y 2),但也给用户的选择来输入自己的x和Y2如果设备尺寸不同,则变量。
根据用户要求,有一个用于使用自定义值的按钮和一个用于使用设备值的按钮。我想将所需的x和y2变量传递给activity2(User)以计算所需的尺寸。我如何根据用户的需要将这些变量传递给activity2。
我是一个相对较新的用户。
Intent intent = new Intent(this, NextActivity.class);
intent.putExtra("x", yourX);
intent.putExtra("y", yourY);
startActivity(intent);
在NextActivity的OnCreate
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
Intent intent = getIntent();
int x = intent.getIntExtra("x",defaultValue);
String y = intent.getStringExtra("y");
if(y == null){
y = yourDefaultYValue;
}
//do something with X and Y
}