Fix race condition regarding message reload.

The method to start ReloadMessageTask() when detecting content
changed events is delay-called, so need to make sure the fragment
is still in the valid state.

Bug 3069896

Change-Id: I1991d902e8044b4f8ca3ffd7d3e2e66005f1e960
This commit is contained in:
Makoto Onuki 2010-10-06 17:40:07 -07:00
parent bb5fd95e75
commit de936b83ac
1 changed files with 11 additions and 0 deletions

View File

@ -834,6 +834,9 @@ public abstract class MessageViewFragmentBase extends Fragment implements View.O
private class ReloadMessageTask extends AsyncTask<Void, Void, Message> {
@Override
protected Message doInBackground(Void... params) {
if (!isMessageSpecified()) { // just in case
return null;
}
return openMessageSync();
}
@ -1378,8 +1381,16 @@ public abstract class MessageViewFragmentBase extends Fragment implements View.O
mThrottle.onEvent();
}
/**
* This method is delay-called by {@link Throttle} on the UI thread. Need to make
* sure if the fragment is still valid. (i.e. don't reload if clearContent() has been
* called.)
*/
@Override
public void run() {
if (!isMessageSpecified()) {
return;
}
Utility.cancelTaskInterrupt(mReloadMessageTask);
mReloadMessageTask = new ReloadMessageTask();
mReloadMessageTask.execute();