2012-03-19 66 views
0

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

+1

您是否了解Android活动生命周期? http://developer.android.com/guide/topics/fundamentals/activities.html – 2012-03-19 02:35:45

回答

2

当你的应用程序正在运行,您会收到一个电话,您的应用程序应该通过重写

onPause() { 
    //save your state here 
} 

方法保存应用程序的当前状态,并实现

onResume() { 
    //load your state here 
} 
+0

如果我的应用程序使用一些线程来接收信息,当一个调用来的时候,线程会停止还是不停止?我是否需要重新启动这些线程? – pthread 2012-03-19 02:47:33

+0

是的,最好的做法是在应用程序暂停时停止运行任何线程,并在调用onResume方法时重新创建/重新启动它们。 – 2012-03-19 02:52:21

+0

@GodwinW伟大的答案,帮助我:) – 2012-03-19 02:53:09

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. 
      } 
     } 
    }