I have a semi-arid problem and hope someone here can help me.
In the click event, I create a thread and start a lengthy operation based on the this method. After completing the long-term task, it performs a callback to another method, which makes a message to the handler:
@Override public void contentSearchModelChanged(Model_ContentSearch csm, ArrayList<Class_Reminder> newRemindersList) { remindersList = newRemindersList; mHandler.post(mUpdateDisplayRunnable); }
What causes Runnable:
// post this to the Handler when the background thread completes private final Runnable mUpdateDisplayRunnable = new Runnable() { public void run() { updateDisplay(); } };
Finally, here is what my updateDisplay () method does:
private void updateDisplay() { if (csModel.getState() != Model_ContentSearch.State.RUNNING) { if(remindersList != null && remindersList.size() > 0){ r_adapter = new ReminderAdapater(Activity_ContentSearch.this, remindersList, thisListView); thisListView.setAdapter(r_adapter); r_adapter.notifyDataSetChanged(); } } }
This works great when I do it normally. However, if I change the orientation during operation for a long time, it does not work. It actually does the callback, and there are items in the reminder list. But when it comes to this line:
r_adapter.notifyDataSetChanged();
Nothing happens. Itβs strange if I give another gift and start the whole process again (without changing the orientation), it actually updates the view twice, once for the previous view and again for the next. Thus, the view is updated once with the results of the first submission, and then again with the results of the second submission the second later. Thus, the DID adapter receives data, it just does not refresh the view.
I know that this has something to do with changing orientation, but I cannot understand why because of my life. Can anyone help? Or can someone suggest an alternative method for handling flows with orientation changes?
Bara
android multithreading listview android-arrayadapter orientation
Bara
source share