Use startActivityForResult(intent, positiveinteger);
做你想做的事,在开始的活动中,当你认为活动已成功完成时,执行setResult(Activity.RESULT_OK);
finish();
并且在开始覆盖的活动中onActivityResult()
方法。并测试您调用的活动是否完成了工作。
从来没有使用过Activity.RESULT_OK
for requestCode
,因为它是负常数。文件说onActivityResult()
将为每个正整数调用方法requestCode
:
重写并遵循这个
如何开始活动以获得结果:
static final int STATIC_RESULT=2; //positive > 0 integer.
Intent i = new Intent("my.activity.startNewOne");
i.putExtra("category", category);
startActivityForResult(i, STATIC_RESULT);
In your startNewOne
您完成的活动的结果如下:
//after the job is done, use the method i mentioned in the comments to check if the sms is delivered/submitted. and proceed if true with this
if(smsObject.getStatus()==0)//by the docs means successfuly sent
{
Intent i = getIntent(); //get the intent that has been called, i.e you did called with startActivityForResult();
i.putExtras(b);//put some data, in a bundle
setResult(Activity.RESULT_OK, i); //now you can use Activity.RESULT_OK, its irrelevant whats the resultCode
finish(); //finish the startNewOne activity
}
你如何使用onActivityResult()
method:
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == STATIC_RESULT) //check if the request code is the one you've sent
{
if (resultCode == Activity.RESULT_OK)
{
// this is successful mission, do with it.
{
} else
// the result code is different from the one you've finished with, do something else.
}
}
super.onActivityResult(requestCode, resultCode, data);
}