I'm writing a method to add phonebook contacts to friend list, if one of my contacts exist in the server the app automatically will add him to my app list friend. The applications works fine, but this method never stop, so how can I do this? I want to search my contacts and compare each contact on server (this is already done) then if contact exist in server add him to contacts list (this is already done too) show contacts when task finish (This is my problem, task never ends, always is reloading )
can anyone help me?
this is my method, it's work good
public void newContactList() {
Thread dt = new Thread(new Runnable() {@Override
public void run() {
try {
Cursor numeros = singleton.getContext().getContentResolver().query(
ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null, null,
null, null);
while (numeros.moveToNext()) {
final String phoneNumber = numeros.getString(numeros.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
String phone = phoneNumber.toString();
String temp = phone.trim();
temp = phone.replaceAll(" ", "");
String tempx = temp.replaceAll("\\((.+?)\\)", "$1");
String tempy = tempx.replaceAll("-", "");
//String tem23 = tempy.replaceAll("+", "");
final String temp2 = tempy;
final String jid = temp2.toString();
ejemplo.version1.ucity.entities.Roster r;
String HOSTT = new String(data4, "UTF-8");
String SERVICEE = new String(data4, "UTF-8");
int PORTT = 5222;
configure(ProviderManager.getInstance());
ConnectionConfiguration connConfig = new ConnectionConfiguration(
HOSTT, PORTT, SERVICEE);
connConfig.setSASLAuthenticationEnabled(false);
XMPPConnection connection = new XMPPConnection(connConfig);
SharedPreferences uname = singleton.getContext().getSharedPreferences("username", singleton.getContext().MODE_PRIVATE);
String jis = uname.getString("username", "");
String text = new String(data2, "UTF-8");
String jidname = jis + text;
String uname1 = jidname.replaceAll(text, "");
SharedPreferences passconfir = singleton.getContext().getSharedPreferences("password", singleton.getContext().MODE_PRIVATE);
String passconf = passconfir.getString("password", "");
connection.connect();
connection.login(uname1, passconf);
Roster roster = connection.getRoster();
roster.getEntry(uname1);
Collection < RosterEntry > entries = roster.getEntries();
String text2 = new String(data, "UTF-8");
String searString2 = text2;
roster.createEntry(searString2, null, null);
if (roster.contains(jid)) {
break;
} else {
UserSearchManager search = new UserSearchManager(connection);
Form searchForm = search.getSearchForm("search." + connection.getServiceName());
Form answerForm = searchForm.createAnswerForm();
answerForm.setAnswer("Username", true);
if (jid.toString().length() >= 10) {
answerForm.setAnswer("search", jid);
org.jivesoftware.smackx.ReportedData data = search.getSearchResults(answerForm, "search." + connection.getServiceName());
if (data.getRows() != null) {
Iterator < ReportedData.Row > it = data.getRows();
while (it.hasNext()) {
ReportedData.Row row = it.next();
Iterator iterator = row.getValues("jid");
Iterator iterator1 = row.getValues("name");
if (iterator.hasNext()) {
String value = iterator.next().toString();
//
String valuename = iterator1.next().toString();
String value2 = value;
String value3 = valuename;
roster.createEntry(value2, value3, null);
}
}
}
} else {
}
};
}
numeros.close();
} catch (Exception e) {
My question is how can I do this task onBack, I tried to do
protected String doInBackground(Void...arg0) {
newContactList();
return
}