Java 创建用于保存信息的按钮
我正在创建一个android应用程序,它使用点击按钮的数据生成存储在共享首选项中的答案。当用户单击按钮时,我很难找到必要的意图代码来保存信息,以便可以使用它来计算答案。从代码中可以看出,当用户单击按钮时,它将生成下一个活动。谢谢Java 创建用于保存信息的按钮,java,android,android-intent,Java,Android,Android Intent,我正在创建一个android应用程序,它使用点击按钮的数据生成存储在共享首选项中的答案。当用户单击按钮时,我很难找到必要的意图代码来保存信息,以便可以使用它来计算答案。从代码中可以看出,当用户单击按钮时,它将生成下一个活动。谢谢 Button button18 = (Button) findViewById(R.id.button18); button18.setOnClickListener(new View.OnClickListener() { @Over
Button button18 = (Button) findViewById(R.id.button18);
button18.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//I need to store the results then move to the next activity shown below?
Intent i = new Intent(EnterAgeActivity.this, EnterWeightActivity.class);
startActivity(i);
// TODO Auto-generated method stub
}
});
`
发送带有意图的数据
@Override
public void onClick(View v) {
//I need to store the results then move to the next activity shown below?
Bundle data = new Bundle();
data.putString(key, value);
data.putInt(key, value);
Intent i = new Intent(EnterAgeActivity.this, EnterWeightActivity.class);
i.putExtra("data", data);
startActivity(i);
}
EnterWeightActivity oncreate:
@Override
public void onCreate(Bundle savedInstanceState) {
Intent intent = getIntent();
if(intent.hasExtras) {
Bundle data = intent.getExtras();
// Your data
}
}
您可以使用共享首选项SSO而不是创建意图我可以使用共享首选项来存储和计算信息?使用共享首选项,您可以存储计算出的值,并在需要时检索它。谢谢,我会尝试一下。