1 回答

TA貢獻(xiàn)1875條經(jīng)驗(yàn) 獲得超3個(gè)贊
如果您只需要保存最多 10 條通話記錄(小數(shù)據(jù)集),那么共享首選項(xiàng)就可以了。
您需要為您的記錄分配一個(gè)唯一的密鑰。
private void saveCallLog(final int callRecordID){
// key here is callRecordID
sharedPrefCallLog = getSharedPreferences("CallLogPref", Context.MODE_PRIVATE);
editorCallLogPref = sharedPrefCallLog.edit();
editorCallLogPref.putString("name_"+ callRecordID, Name);
editorCallLogPref.putString("num_"+ callRecordID, Number);
editorCallLogPref.putString("city_"+ callRecordID,City);
editorCallLogPref.apply();
}
要獲取通話記錄詳細(xì)信息,請使用
private void getCallDetails(int callRecordID){
sharedPrefCallLog.getString("name_"+ callRecordID, null);
sharedPrefCallLog.getString("num_"+ callRecordID, null);
sharedPrefCallLog.getString("city_"+ callRecordID, null);
}
添加回答
舉報(bào)