[英]Incoming call Notification using sinch in Android ,I am Using FireBase Messaging service but not getting calls when app is killed in background
[英]Android application getting killed because of incoming call
在我的應用程序中,我將所有呼叫日志復制到異步任務中的數據庫中。 但是,如果在兩次調用之間發生調用,我的應用程序可能會終止,從而導致數據不完整。 因此,首先我想阻止我的應用程序在這種情況下被終止,那我該怎么辦? 我也想跟蹤光標,以便當再次打開應用程序時,它將從停止並完成作業的完全相同的位置繼續。
這是幫助我在來電時保存游戲狀態的代碼。希望也能對您有所幫助...
TelephonyManager tm;
private PhoneStateListener mPhoneListener = new PhoneStateListener() {
public void onCallStateChanged(int state, String incomingNumber) {
try {
switch (state) {
case TelephonyManager.CALL_STATE_RINGING:
Toast.makeText(GameActivity.this, "CALL_STATE_RINGING", Toast.LENGTH_SHORT).show();
//Your function to save state right here...
stopTimer();
break;
case TelephonyManager.CALL_STATE_OFFHOOK:
Toast.makeText(GameActivity.this, "CALL_STATE_OFFHOOK", Toast.LENGTH_SHORT).show();
break;
case TelephonyManager.CALL_STATE_IDLE:
Toast.makeText(GameActivity.this, "CALL_STATE_IDLE", Toast.LENGTH_SHORT).show();
break;
default:
Toast.makeText(GameActivity.this, "default", Toast.LENGTH_SHORT).show();
Log.i("Default", "Unknown phone state=" + state);
}
} catch (Exception e) {
Log.i("Exception", "PhoneStateListener() e = " + e);
}
}
};
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.