我有一个Android应用程序,我在按钮单击时调用Intent调用Intent。调用意图的示例代码如下。
Intent callIntent = new Intent(Intent.ACTION_CALL);
callIntent.setData(Uri.parse("tel:"+phoneNumber));
callIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(callIntent);
在呼叫完成后,我被返回到我调用此呼叫意图的活动。现在我的问题是,我知道我从呼叫意图返回的任何方式。我不是从活动中称之为
答案 0 :(得分:1)
要了解已开始的活动结束并从中获取结果,您通常应使用startActivityForResult
,然后onActivityResult
将在通话活动中执行。
答案 1 :(得分:0)
FirstActivity:
public static final REQUEST_CODE = 1; // field
/* # TODO
Your intent type instantiation and settings here */
startActivityForResult(callIntent, REQUEST_CODE); // # Calling second activity
@Override
protected void onActivityResult (int requestCode, int resultCode, Intent data)
{
if (requestCode == REQUEST_CODE && resultCode == SecondActivity.RESULT_OK) // # Will inform you if second activity is finished and the result
{
// # TODO : Implement your logic here
}
}
SecondActivity;在致电finish()
之前:
public static final RESULT_OK = 8; // field
// # Set result to OK or define a second flag RESULT_CANCEL = <any number> and set it
setResult(RESULT_OK);
finish();