I am writing an Android application, there is a list of contacts that I receive from the server and write to the database. And when I display the data on the screen, they are not displayed in the order in which they were received (always in different), and not all data.
Method for writing to the database
public void addRec(final String firstName, final String lastName, final String image) { new Thread(new Runnable() { @Override public void run() { ContentValues cv = new ContentValues(); cv.put(COLUMN_FNAME, firstName); cv.put(COLUMN_LNAME, lastName); cv.put(COLUMN_URL, image); sql.insertOrThrow(TABLE_FRIENDS, null, cv); } }).start(); } called in a loop
public static void updateBase (final Context context){ Contract contract=new Contract(context); contract.openDB(); contract.delete(); for(int i=0;i<friends.size();i++) { contract.addRec(friends.get(i).first_name, friends.get(i).last_name, friends.get(i).photo); } } Why is the data order broken? How to fix?