我用2个活动1和2制作应用程序,并想共享在第2页的文本视图中写入的文字1中的直接计算中的计算2中的"在此页面2"中查看。(例如,如果第一个文本视图包含编号10,我想在"值 10"(例如" value 10")中使用此数字,并且该结果将在第2页的文本视图中查看
您可以通过捆绑包
将其传递Intent intent = new Intent(this, OtherActivity.class);
Bundle bundle = new Bundle();
bundle.putInt("something", 1);
intent.putExtras(bundle);
startActivity(intent);
在您的其他活动中:
Bundle bundle = getIntent().getExtras();
int something;
if (bundle != null) {
something = bundle.getInt("something");
}else{
//
}
这样,您可以将一堆参数传递给下一个活动。
Activity1
中的代码Intent intent = new Intent(this, Activity2.class);
intent.putExtra("number", 10);
startActivity(intent);
Activity 2
中的代码int number = getIntent().getIntExtra("number", 0);