java.lang.IllegalStateException:结果未挂起时调用

时间:2015-06-17 12:28:12

标签: java android

我正在创建拨号器,我想在点击按钮时断开呼叫,我正在尝试

public class OutgoingCallListener extends BroadcastReceiver {

    @Override
    public void onReceive(Context context, Intent intent) {     
            setResultData(null);
    }

}

这里我在按钮onclick功能中调用

try{
        OutgoingCallListener out = new  OutgoingCallListener();
        Intent intent = new Intent();
        out.onReceive(this, intent);    
    }catch(Exception e){
        Log.i("ii", "exception in end call", e);
    }

此处完成日志跟踪

exception in end call
    06-17 17:48:05.282: I/ii(17159): java.lang.IllegalStateException: Call while result is not pending
    06-17 17:48:05.282: I/ii(17159):    at android.content.BroadcastReceiver.checkSynchronousHint(BroadcastReceiver.java:780)
    06-17 17:48:05.282: I/ii(17159):    at android.content.BroadcastReceiver.setResultData(BroadcastReceiver.java:586)
    06-17 17:48:05.282: I/ii(17159):    at me.cs.oicalls.OutgoingCallListener.onReceive(OutgoingCallListener.java:14)
    06-17 17:48:05.282: I/ii(17159):    at me.cs.oicalls.CallOut.endCall(CallOut.java:106)
    06-17 17:48:05.282: I/ii(17159):    at java.lang.reflect.Method.invokeNative(Native Method)
    06-17 17:48:05.282: I/ii(17159):    at java.lang.reflect.Method.invoke(Method.java:525)
    06-17 17:48:05.282: I/ii(17159):    at android.view.View$1.onClick(View.java:3602)
    06-17 17:48:05.282: I/ii(17159):    at android.view.View.performClick(View.java:4212)
    06-17 17:48:05.282: I/ii(17159):    at android.view.View$PerformClick.run(View.java:17476)
    06-17 17:48:05.282: I/ii(17159):    at android.os.Handler.handleCallback(Handler.java:800)
    06-17 17:48:05.282: I/ii(17159):    at android.os.Handler.dispatchMessage(Handler.java:100)
    06-17 17:48:05.282: I/ii(17159):    at android.os.Looper.loop(Looper.java:194)
    06-17 17:48:05.282: I/ii(17159):    at android.app.ActivityThread.main(ActivityThread.java:5371)
    06-17 17:48:05.282: I/ii(17159):    at java.lang.reflect.Method.invokeNative(Native Method)
    06-17 17:48:05.282: I/ii(17159):    at java.lang.reflect.Method.invoke(Method.java:525)
    06-17 17:48:05.282: I/ii(17159):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:833)
    06-17 17:48:05.282: I/ii(17159):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
    06-17 17:48:05.282: I/ii(17159):    at dalvik.system.NativeStart.main(Native Method)

1 个答案:

答案 0 :(得分:0)

为什么要调用onReceive方法?

当触发该事件时,会自动调用 BroadcastReceiver的onRecive()方法(如果你注册的话是OutgoingCallListener)