사용자 연락처를 Parse.com 대시 보드에 저장하려고합니다. 프로젝트를 다시 실행하여 & 연락처를 다시 저장합니다.연락처를 저장할 때 데이터 손실이 발생했습니다.
하지만 연락처가 여러 개 저장 될 때마다 연락처 중 일부 (데이터 즉, 친구 & 전화 번호)가 손실되었습니다.
나는 모든이 코드를 사용하고 있습니다 :
public class MainActivity extends Activity {
ParseObject testObject;
EditText et;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Parse.initialize(this, "2dSVesLx7lUKxhSb7B4bSmAOlIVAWONM8sIQTtZb", "CkikNpzXV2eR0QugHnZCQoQjbh6IDgHrESG0KIBS");
et = (EditText)findViewById(R.id.editText1);
et.setOnEditorActionListener(new OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
boolean handled = false;
if (actionId == EditorInfo.IME_ACTION_DONE) {
// TODO do something
handled = true;
testObject = new ParseObject("India"+et.getText().toString());
readDistinctContacts("India"+et.getText().toString());
// readContacts();
}
return handled;
}
});
}
public void readDistinctContacts(String s) {
ContentResolver cr = getContentResolver();
Cursor cur = cr.query(ContactsContract.Contacts.CONTENT_URI, null, null, null, null);
ArrayList<ParseObject> contacts = new ArrayList<ParseObject>();
ArrayList<String> list = new ArrayList<String>();
if (cur.getCount() > 0) {
while (cur.moveToNext()) {
String id = cur.getString(cur.getColumnIndex(ContactsContract.Contacts._ID));
String name = cur.getString(cur.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME));
if (Integer.parseInt(cur.getString(cur.getColumnIndex(ContactsContract.Contacts.HAS_PHONE_NUMBER))) == 1) {
System.out.println(name);
ParseObject testObject = new ParseObject(s);
testObject.put("names", name);
// get the phone number
Cursor pCur = cr.query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null, ContactsContract.CommonDataKinds.Phone.CONTACT_ID + " = ?", new String[] { id }, null);
while (pCur.moveToNext()) {
String phone = pCur.getString(pCur.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
System.out.println(phone);
testObject.put("phonenumber", phone);
if(!list.contains(phone)) {
contacts.add(testObject);
}
list.add(phone);
}
pCur.close();
testObject.saveInBackground();
}
}
}
cur.close();
}
public void readContacts(){
ContentResolver cr = getContentResolver();
Cursor cur = cr.query(ContactsContract.Contacts.CONTENT_URI,null, null, null, null);
if (cur.getCount() > 0) {
while (cur.moveToNext()) {
String id = cur.getString(cur.getColumnIndex(ContactsContract.Contacts._ID));
String name = cur.getString(cur.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME));
if (Integer.parseInt(cur.getString(cur.getColumnIndex(ContactsContract.Contacts.HAS_PHONE_NUMBER))) ==1) {
System.out.println(name);
ParseObject testObject = new ParseObject("India"+et.getText().toString());
testObject.put("names", name);
// testObject.saveInBackground();
// get the phone number
Cursor pCur = cr.query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI,null,
ContactsContract.CommonDataKinds.Phone.CONTACT_ID +" = ?",
new String[]{id}, null);
while (pCur.moveToNext()) {
String phone = pCur.getString(
pCur.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
System.out.println(phone);
testObject.put("phonenumber", phone);
}
pCur.close();
testObject.saveInBackground();
}
}
}
}
}
나는 코드 readcontacts()
, readDistinctContacts()
처럼 두 방법을 사용했지만, 모두는 나에게 같은 문제를주고있다. 대시 보드의 스냅 샷을 보면 매번 다른 연락처 수가 표시됩니다.
이 문제를 해결하려면 어떤 해결책이 있습니까? 사전
UPDATE askoka에
감사에서
감사합니다,이 데이터 손실이 없었다하지만 400 parseobjects (예. 연락처) 400 푸시 요청에 의해 저장 3-4 분 정도 소요 saveEventually()를 사용! . 스토리지를 빠르고 효율적으로 만들고 싶습니다. 누구나 내가 할 수있는 최선의 방법을 말해 줄 수 있습니까?
추가 할 수있는'에서 System.out.println (cur.getCount()); '당신이 변수를 생성하고 항상 접촉 같은 양의 결과 있는지 확인 후? – Dehli
예 712 같은 수량의 연락처! 그리고 logcat에서 다음 경고 메시지가 나타납니다. close close()없이 완료된 커서 –
예 712와 같은 양의 연락처! 그리고 나는 또한이 경고를 받는다 : 이전 close()없이 완료된 커서 –