Fixed crashes in FeedItemlist

This commit is contained in:
daniel oeh 2013-09-21 12:11:06 +02:00
parent 4d50903182
commit 0b0ea77df1
2 changed files with 27 additions and 4 deletions

View File

@ -49,6 +49,8 @@ public class FeedItemlistActivity extends ActionBarActivity {
private ItemlistFragment filf;
private ExternalPlayerFragment externalPlayerFragment;
private AsyncTask<?, ?, ?> currentLoadTask;
@Override
public void onCreate(Bundle savedInstanceState) {
setTheme(UserPreferences.getTheme());
@ -70,7 +72,10 @@ public class FeedItemlistActivity extends ActionBarActivity {
}
private void loadData(long id) {
private synchronized void loadData(long id) {
if (currentLoadTask != null) {
currentLoadTask.cancel(true);
}
AsyncTask<Long, Void, Feed> loadTask = new AsyncTask<Long, Void, Feed>() {
@Override
@ -80,6 +85,12 @@ public class FeedItemlistActivity extends ActionBarActivity {
return DBReader.getFeed(FeedItemlistActivity.this, longs[0]);
}
@Override
protected void onCancelled(Feed feed) {
super.onCancelled(feed);
if (AppConfig.DEBUG) Log.d(TAG, "load task was cancelled");
}
@Override
protected void onPostExecute(Feed result) {
super.onPostExecute(result);
@ -103,6 +114,7 @@ public class FeedItemlistActivity extends ActionBarActivity {
}
}
};
currentLoadTask = loadTask;
loadTask.execute(id);
}
@ -112,6 +124,14 @@ public class FeedItemlistActivity extends ActionBarActivity {
StorageUtils.checkStorageAvailability(this);
}
@Override
protected void onStop() {
super.onStop();
if (currentLoadTask != null) {
currentLoadTask.cancel(true);
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
super.onCreateOptionsMenu(menu);

View File

@ -125,21 +125,24 @@ public class ItemlistFragment extends ListFragment {
}
@Override
public void onDestroyView() {
super.onDestroyView();
public void onStop() {
super.onStop();
EventDistributor.getInstance().unregister(contentUpdate);
if (currentLoadTask != null) {
currentLoadTask.cancel(true);
}
}
protected void loadData() {
protected synchronized void loadData() {
final long feedId;
if (feed == null) {
feedId = getArguments().getLong(ARGUMENT_FEED_ID);
} else {
feedId = feed.getId();
}
if (currentLoadTask != null) {
currentLoadTask.cancel(true);
}
AsyncTask<Long, Void, Feed> loadTask = new AsyncTask<Long, Void, Feed>(){
private volatile List<Long> queueRef;