Fix thread issue
This commit is contained in:
parent
af3d82ae8d
commit
f4da9df32f
1 changed files with 37 additions and 24 deletions
|
@ -57,6 +57,7 @@ public class ContactsFragment extends Fragment implements OnClickListener, OnIte
|
||||||
private int lastKnownPosition;
|
private int lastKnownPosition;
|
||||||
private Cursor cursor;
|
private Cursor cursor;
|
||||||
private List<Contact> contacts;
|
private List<Contact> contacts;
|
||||||
|
private Thread contactsHandler;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||||
|
@ -111,16 +112,17 @@ public class ContactsFragment extends Fragment implements OnClickListener, OnIte
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
|
||||||
cursor = Compatibility.getContactsCursor(getActivity().getContentResolver());
|
cursor = Compatibility.getContactsCursor(getActivity().getContentResolver());
|
||||||
contacts = new ArrayList<Contact>();
|
contactsHandler = new Thread(new Runnable() {
|
||||||
new Thread(new Runnable() {
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
|
contacts = new ArrayList<Contact>();
|
||||||
for (int i = 0; i < cursor.getCount(); i++) {
|
for (int i = 0; i < cursor.getCount(); i++) {
|
||||||
Contact contact = getContact(i);
|
Contact contact = getContact(i);
|
||||||
contacts.add(contact);
|
contacts.add(contact);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}).start();
|
});
|
||||||
|
contactsHandler.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -138,7 +140,14 @@ public class ContactsFragment extends Fragment implements OnClickListener, OnIte
|
||||||
contactsList.setSelectionFromTop(lastKnownPosition, 0);
|
contactsList.setSelectionFromTop(lastKnownPosition, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onPause() {
|
||||||
|
contactsHandler.interrupt();
|
||||||
|
super.onPause();
|
||||||
|
}
|
||||||
|
|
||||||
private Contact getContact(int position) {
|
private Contact getContact(int position) {
|
||||||
|
try {
|
||||||
cursor.moveToFirst();
|
cursor.moveToFirst();
|
||||||
boolean success = cursor.move(position);
|
boolean success = cursor.move(position);
|
||||||
if (!success)
|
if (!success)
|
||||||
|
@ -160,6 +169,10 @@ public class ContactsFragment extends Fragment implements OnClickListener, OnIte
|
||||||
contact.setNumerosOrAddresses(Compatibility.extractContactNumbersAndAddresses(contact.getID(), getActivity().getContentResolver()));
|
contact.setNumerosOrAddresses(Compatibility.extractContactNumbersAndAddresses(contact.getID(), getActivity().getContentResolver()));
|
||||||
|
|
||||||
return contact;
|
return contact;
|
||||||
|
} catch (Exception e) {
|
||||||
|
|
||||||
|
}
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
class ContactsListAdapter extends BaseAdapter implements SectionIndexer {
|
class ContactsListAdapter extends BaseAdapter implements SectionIndexer {
|
||||||
|
|
Loading…
Reference in a new issue