问题描述
我正在开发一个应用程序,并已能够开始在应用程序中的电话,但是当它结束时,我想恢复与信息preserved和弹出应用程序上来。
I am developing an app and have been able to start a phone call inside the app but when it end I want to resume the app with the information preserved and a pop up to come up.
我已经能够拨打电话,并得到弹出来在单独的实例,但不能把它们放在一起。这个问题已经回答了在今年三月份,但我想看看是否有人想出了一个更好的主意。谢谢你。
I have been able to dial the call and get the pop up to come up in seperate instances but unable to put them together. This question has been answered in March of this year but I wanted to see if anyone else has come up with a better idea. Thank you.
推荐答案
综观活动生命周期图中,当一个电话接收应用程序调用的onPause()
方法。我能想到的是给你用从一个线程共享preferences
写入数据,而这将运行该应用程序是否不再可见做你的数据的保存给用户,无论你在通话监听器或的onPause()
办法做到这一点。但更实用的方法是使用你放置),这将最近在 onRestoreInstanceState恢复(所有的相关数据$ C
的onSaveInstanceState()
方法$ C>方法。
Looking at the Activity Life cycle diagram, when a phone call is received application calls onPause()
method. What I can think of is for you to do a saving of your data using SharedPreferences
writing data from a thread which will run regardless if the application is not visible anymore to the user, either you do this in the call listener or in onPause()
method. But more practical approach is to use onSaveInstanceState()
method where you put all the relevant data which will be restored lately in onRestoreInstanceState()
method.
在这里阅读更多它们是如何工作:
Read more here how they work:
http://developer.android.com/reference/android/app/Activity.html#onRestoreInstanceState(android.os.Bundle)
http://developer.android.com/reference/android/app/Activity.html#onSaveInstanceState(android.os.Bundle)
http://developer.android.com/reference/android/telephony/PhoneStateListener.html
在 PhoneStateListener
类,你可以使用一些标记
标记,如果呼叫已经发生,去的时候 CALL_STATE_RINGING
状态,然后在 CALL_STATE_IDLE
检查调用是否是由因为IDLE状态正在发生一切的时候,手机在做什么,但是当你有一个标志,你可以检查 IF(标志)
做一些事情,改变标志,所以每当听众又是 CALL_STATE_IDLE
您的标志将被反转,再次将采取任何动作。只是一个想法。
In the PhoneStateListener
class you can use some flags
to mark if the call has taken place, when going to CALL_STATE_RINGING
state, and then in the CALL_STATE_IDLE
check whether call is made because IDLE state is occuring all the time when the phone is doing nothing, but when you have a flag you can check if(flag)
do something and change the flag, so whenever the listener is again in CALL_STATE_IDLE
your flag will be inverted so no actions again will be taken. Just an idea.
的 修改的添加的PhoneStateListener类作为内部类中的活动/服务类和使用注册手机状态监听器 TelephonyManager
。我希望你能找到你的方式。
Add the the PhoneStateListener class as inner class in your activity/service class and register phone state listener using TelephonyManager
. I hope you'll find your way
public class MyClassActivity extends Activity
{
....
//set here your call listener here
}
protected class PhoneState extends PhoneStateListener{
private boolean mCall=false;
@Override
public void onCallStateChanged(int state, String incomingNumber) {
switch(state)
{
case TelephonyManager.CALL_STATE_RINGING:
mCall=true; //fire the flag that there is call ongoing
break;
case TelephonyManager.CALL_STATE_IDLE:
if(mCall)
{
mCall=false; //Reverting the flag, indicating you are aware that there was call
// Here do the rest of your operation you want
}
break;
default:
}
super.onCallStateChanged(state, incomingNumber);
}
}
这篇关于结束通话后,Android开始方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!