首先创建一个MAIN.java 活动来容纳您的其他活动。就像其他人所说的那样,您将不得不对捕获自己的按钮进行编码,因为如果您要尝试处理意图,那应该是常识。但是,当您将它们组合在一起时,您可以通过以下意图开始一个新活动:
// allocate new intent, initialized to the activity you wish to launch
Intent i = new Intent(this, ActivityToBeLaunched.class);
// put information into intent
i.putExtras("KeyName", value); // where "KeyName" is simply a reference string
// and 'value' can be anything from boolean - string.
// launch activity and wait for response
startActivityForResult(i, REQUEST_CODE);
然后在您的 ActivityToBeLaunched.java 类中,您将拥有一个 oncreate,它将从 Intent 中提取信息,如下所示:
// get intent
Intent i = this.getIntent();
// get information from intent
booleanVariable = i.getExtras().getBoolean("KeyName");
完成此活动后,只需使用;
// create intent
Intent i = new Intent();
// put information into result to send back to parent
i.putExtras("KeyName", value);
// set the result to be returned
setResult(i, ResultCode);
// finish child, return to parent with results
finish();