如何在呼叫到来之后保持android运行?

时间:2012-03-19 02:31:21

标签: android call

我的应用程序似乎在通话后停止,如何让它保持运行并在通话前保持状态?

2 个答案:

答案 0 :(得分:2)

当您的应用程序正在运行并且您接到电话时,您的应用应通过覆盖来保存应用当前状态

onPause() {
    //save your state here
}

方法,并实施

onResume() {
    //load your state here
}

答案 1 :(得分:1)

您可以使用PhoneStateListener在通话结束后开始上一个活动。

class CallEndedListener extends PhoneStateListener {
        boolean called = false;

        @Override
        public void onCallStateChanged(int state, String incomingNumber) {
            super.onCallStateChanged(state, incomingNumber);

            if (state == TelephonyManager.CALL_STATE_OFFHOOK)
                called = true;

            if (called && state == TelephonyManager.CALL_STATE_IDLE) {
                called = false;
                // do something here.
            }
        }
    }