I have a list in which I want to add data that I take from the database. There is a func function where I add entries to my list . It would seem that after the called function, the size of the list should increase. To verify this, I checked the size immediately after calling the func function. But the size was equal to zero. But if you check the size of the list inside the func function, then it is not at all zero. What could be the reason? I think I do not know some simple basic thing.
PS: For readability, I minimized the size of the code
public class TaskActivity extends AppCompatActivity { ArrayList<Task> list ; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_task); list = new ArrayList<>() ; func() ; // вызов функции tx.setText("Size:" + list.size()); //проверка размера } public void func() { Backendless.Persistence.of(Task.class).find(new AsyncCallback<BackendlessCollection<Task>>() { @Override public void handleResponse(BackendlessCollection<Task> response) { Iterator<Task> it = response.getCurrentPage().iterator(); while(it.hasNext()) { Task t = it.next() ; list.add(t) ; } //tx.setText("Size:" + list.size()); // проверка размера внутри функции } @Override public void handleFault(BackendlessFault fault) { Toast.makeText(getApplicationContext() , "WRONG!!!" , Toast.LENGTH_SHORT).show(); } }) ; } }