我正在实现一个简单的应用程序。我需要根据活动的状态启动活动。让我们假设我正在使用一个按钮来启动活动。1.如果活动没有启动,我需要启动XYZ活动。2.如果XYZ活动是焦点,那么我需要在按下按钮时关闭该活动。3.如果XYZ活动未处于焦点(如onPause)状态,则需要更改按钮状态。
您可以帮助我在旗帜,我需要用来开始意图。是否可以在开始该活动之前获取活动的状态?
发布于 2010-08-09 13:19:07
尝尝这个
Intent =新Intent(currentActivity.this,callingActivity.class);startActivity( intent );
您可以像这样使用intent来调用一个活动
发布于 2010-08-09 16:07:21
按钮按下将需要由每个活动单独捕获,所以只需将不同的响应编码到每个不同的活动中。
发布于 2011-04-09 22:26:20
首先,创建一个MAIN.java活动,该活动将容纳您的其他活动。就像其他人所说的那样,你必须自己编写按钮捕获的代码,因为如果你试图处理意图,这应该是常识。但是,当您获得这些内容时,您可以通过intent启动一个新的活动,如下所示:
// 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();https://stackoverflow.com/questions/3436970
复制相似问题