我怎么知道我从android中的通话意图回来了?

时间:2014-01-06 13:37:17

标签: android android-intent call

我有一个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);

在呼叫完成后,我被返回到我调用此呼叫意图的活动。现在我的问题是,我知道我从呼叫意图返回的任何方式。我不是从活动中称之为

2 个答案:

答案 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();
相关问题