Fixed a bug that AsyncTasks were not working properly on api 11+
This commit is contained in:
parent
7cde39efd2
commit
57b41eb18e
@ -1,6 +1,7 @@
|
||||
package de.danoeh.antennapod.activity;
|
||||
|
||||
import android.graphics.drawable.BitmapDrawable;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.app.FragmentManager;
|
||||
import android.support.v4.app.FragmentTransaction;
|
||||
@ -90,7 +91,12 @@ public class FeedItemlistActivity extends SherlockFragmentActivity {
|
||||
finish();
|
||||
}
|
||||
};
|
||||
remover.execute(feed);
|
||||
if (android.os.Build.VERSION.SDK_INT > android.os.Build.VERSION_CODES.GINGERBREAD_MR1) {
|
||||
remover.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR,
|
||||
feed);
|
||||
} else {
|
||||
remover.execute(feed);
|
||||
}
|
||||
break;
|
||||
case android.R.id.home:
|
||||
finish();
|
||||
|
@ -1,5 +1,6 @@
|
||||
package de.danoeh.antennapod.activity;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.AlertDialog;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.ComponentName;
|
||||
@ -142,7 +143,8 @@ public class MediaplayerActivity extends SherlockFragmentActivity implements
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
switch (item.getItemId()) {
|
||||
case android.R.id.home:
|
||||
startActivity(new Intent(MediaplayerActivity.this, MainActivity.class));
|
||||
startActivity(new Intent(MediaplayerActivity.this,
|
||||
MainActivity.class));
|
||||
break;
|
||||
default:
|
||||
return FeedItemMenuHandler.onMenuItemClicked(this, item,
|
||||
@ -284,8 +286,10 @@ public class MediaplayerActivity extends SherlockFragmentActivity implements
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressLint("NewApi")
|
||||
private void setupPositionObserver() {
|
||||
if (positionObserver == null || positionObserver.isCancelled()) {
|
||||
Log.d(TAG, "Setting up position observer");
|
||||
positionObserver = new MediaPositionObserver() {
|
||||
|
||||
@Override
|
||||
@ -301,7 +305,14 @@ public class MediaplayerActivity extends SherlockFragmentActivity implements
|
||||
}
|
||||
|
||||
};
|
||||
positionObserver.execute(playbackService.getPlayer());
|
||||
if (android.os.Build.VERSION.SDK_INT > android.os.Build.VERSION_CODES.GINGERBREAD_MR1) {
|
||||
positionObserver.executeOnExecutor(
|
||||
AsyncTask.THREAD_POOL_EXECUTOR,
|
||||
playbackService.getPlayer());
|
||||
} else {
|
||||
positionObserver.execute(playbackService.getPlayer());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -317,8 +328,7 @@ public class MediaplayerActivity extends SherlockFragmentActivity implements
|
||||
if (!mediaInfoLoaded) {
|
||||
Log.d(TAG, "Loading media info");
|
||||
if (media != null) {
|
||||
getSupportActionBar().setSubtitle(
|
||||
media.getItem().getTitle());
|
||||
getSupportActionBar().setSubtitle(media.getItem().getTitle());
|
||||
getSupportActionBar().setTitle(
|
||||
media.getItem().getFeed().getTitle());
|
||||
if (orientation == Configuration.ORIENTATION_PORTRAIT) {
|
||||
@ -461,12 +471,18 @@ public class MediaplayerActivity extends SherlockFragmentActivity implements
|
||||
}
|
||||
};
|
||||
|
||||
@SuppressLint("NewApi")
|
||||
private void setupVideoControlsToggler() {
|
||||
if (videoControlsToggler != null) {
|
||||
videoControlsToggler.cancel(true);
|
||||
}
|
||||
videoControlsToggler = new VideoControlsHider();
|
||||
videoControlsToggler.execute();
|
||||
if (android.os.Build.VERSION.SDK_INT > android.os.Build.VERSION_CODES.GINGERBREAD_MR1) {
|
||||
videoControlsToggler.executeOnExecutor(
|
||||
AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
} else {
|
||||
videoControlsToggler.execute();
|
||||
}
|
||||
}
|
||||
|
||||
private void toggleVideoControlsVisibility() {
|
||||
|
@ -66,7 +66,11 @@ public class FeedImageLoader {
|
||||
} else {
|
||||
target.setImageResource(R.drawable.default_cover);
|
||||
BitmapWorkerTask worker = new BitmapWorkerTask(target);
|
||||
worker.execute(image);
|
||||
if (android.os.Build.VERSION.SDK_INT > android.os.Build.VERSION_CODES.GINGERBREAD_MR1) {
|
||||
worker.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, image);
|
||||
} else {
|
||||
worker.execute(image);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
target.setImageResource(R.drawable.default_cover);
|
||||
|
@ -3,6 +3,7 @@ package de.danoeh.antennapod.asynctask;
|
||||
import org.shredzone.flattr4j.exception.FlattrException;
|
||||
import org.shredzone.flattr4j.oauth.AccessToken;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.Context;
|
||||
import android.os.AsyncTask;
|
||||
import android.util.Log;
|
||||
@ -78,5 +79,14 @@ public class FlattrClickWorker extends AsyncTask<Void, Void, Void> {
|
||||
return null;
|
||||
}
|
||||
|
||||
@SuppressLint("NewApi")
|
||||
public void executeAsync() {
|
||||
if (android.os.Build.VERSION.SDK_INT > android.os.Build.VERSION_CODES.GINGERBREAD_MR1) {
|
||||
executeOnExecutor(THREAD_POOL_EXECUTOR);
|
||||
} else {
|
||||
execute();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -78,5 +78,13 @@ public class FlattrTokenFetcher extends AsyncTask<Void, Void, AccessToken> {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public void executeAsync() {
|
||||
if (android.os.Build.VERSION.SDK_INT > android.os.Build.VERSION_CODES.GINGERBREAD_MR1) {
|
||||
executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
} else {
|
||||
execute();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -8,6 +8,7 @@ import de.danoeh.antennapod.service.DownloadService;
|
||||
import de.danoeh.antennapod.storage.DownloadRequester;
|
||||
import de.danoeh.antennapod.util.FeedMenuHandler;
|
||||
import de.danoeh.antennapod.R;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Bundle;
|
||||
import android.app.Activity;
|
||||
import android.view.View;
|
||||
@ -163,7 +164,11 @@ public class FeedlistFragment extends SherlockListFragment implements
|
||||
fla.notifyDataSetChanged();
|
||||
}
|
||||
};
|
||||
remover.execute(selectedFeed);
|
||||
if (android.os.Build.VERSION.SDK_INT > android.os.Build.VERSION_CODES.GINGERBREAD_MR1) {
|
||||
remover.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, selectedFeed);
|
||||
} else {
|
||||
remover.execute(selectedFeed);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -5,6 +5,7 @@ import java.net.URLEncoder;
|
||||
|
||||
import org.apache.commons.lang3.StringEscapeUtils;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.Activity;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Bundle;
|
||||
@ -36,7 +37,8 @@ public class ItemDescriptionFragment extends SherlockFragment {
|
||||
|
||||
private AsyncTask<Void, Void, Void> webViewLoader;
|
||||
|
||||
public static ItemDescriptionFragment newInstance(FeedItem item, boolean scrollbarEnabled) {
|
||||
public static ItemDescriptionFragment newInstance(FeedItem item,
|
||||
boolean scrollbarEnabled) {
|
||||
ItemDescriptionFragment f = new ItemDescriptionFragment();
|
||||
Bundle args = new Bundle();
|
||||
args.putLong(ARG_FEED_ID, item.getFeed().getId());
|
||||
@ -54,12 +56,17 @@ public class ItemDescriptionFragment extends SherlockFragment {
|
||||
return webvDescription;
|
||||
}
|
||||
|
||||
@SuppressLint("NewApi")
|
||||
@Override
|
||||
public void onAttach(Activity activity) {
|
||||
super.onAttach(activity);
|
||||
if (webViewLoader == null && item != null) {
|
||||
webViewLoader = createLoader();
|
||||
webViewLoader.execute();
|
||||
if (android.os.Build.VERSION.SDK_INT > android.os.Build.VERSION_CODES.GINGERBREAD_MR1) {
|
||||
webViewLoader.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
} else {
|
||||
webViewLoader.execute();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -91,7 +98,11 @@ public class ItemDescriptionFragment extends SherlockFragment {
|
||||
Feed feed = manager.getFeed(feedId);
|
||||
item = manager.getFeedItem(itemId, feed);
|
||||
webViewLoader = createLoader();
|
||||
webViewLoader.execute();
|
||||
if (android.os.Build.VERSION.SDK_INT > android.os.Build.VERSION_CODES.GINGERBREAD_MR1) {
|
||||
webViewLoader.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
} else {
|
||||
webViewLoader.execute();
|
||||
}
|
||||
} else {
|
||||
Log.e(TAG, TAG + " was called with invalid arguments");
|
||||
}
|
||||
|
@ -27,6 +27,7 @@ import de.danoeh.antennapod.storage.DownloadRequester;
|
||||
import de.danoeh.antennapod.syndication.handler.FeedHandler;
|
||||
import de.danoeh.antennapod.syndication.handler.UnsupportedFeedtypeException;
|
||||
import de.danoeh.antennapod.util.DownloadError;
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.Notification;
|
||||
import android.app.NotificationManager;
|
||||
import android.app.PendingIntent;
|
||||
@ -43,6 +44,7 @@ import android.graphics.Bitmap;
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.support.v4.app.NotificationCompat;
|
||||
import android.util.Log;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Binder;
|
||||
import android.os.Debug;
|
||||
import android.os.Handler;
|
||||
@ -95,6 +97,7 @@ public class DownloadService extends Service {
|
||||
return super.onStartCommand(intent, flags, startId);
|
||||
}
|
||||
|
||||
@SuppressLint("NewApi")
|
||||
@Override
|
||||
public void onCreate() {
|
||||
Log.d(TAG, "Service started");
|
||||
@ -108,7 +111,11 @@ public class DownloadService extends Service {
|
||||
downloadManager = (DownloadManager) getSystemService(Context.DOWNLOAD_SERVICE);
|
||||
downloadObserver = new DownloadObserver(this);
|
||||
setupNotification();
|
||||
downloadObserver.execute();
|
||||
if (android.os.Build.VERSION.SDK_INT > android.os.Build.VERSION_CODES.GINGERBREAD_MR1) {
|
||||
downloadObserver.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
} else {
|
||||
downloadObserver.execute();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -2,6 +2,7 @@ package de.danoeh.antennapod.service;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.PendingIntent;
|
||||
import android.app.Service;
|
||||
import android.content.BroadcastReceiver;
|
||||
@ -330,6 +331,7 @@ public class PlaybackService extends Service {
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressLint("NewApi")
|
||||
private void setupPositionSaver() {
|
||||
if (positionSaver != null && !positionSaver.isCancelled()) {
|
||||
positionSaver.cancel(true);
|
||||
@ -347,7 +349,11 @@ public class PlaybackService extends Service {
|
||||
positionSaver = null;
|
||||
}
|
||||
};
|
||||
positionSaver.execute();
|
||||
if (android.os.Build.VERSION.SDK_INT > android.os.Build.VERSION_CODES.GINGERBREAD_MR1) {
|
||||
positionSaver.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
} else {
|
||||
positionSaver.execute();
|
||||
}
|
||||
}
|
||||
|
||||
private MediaPlayer.OnPreparedListener preparedListener = new MediaPlayer.OnPreparedListener() {
|
||||
@ -561,7 +567,11 @@ public class PlaybackService extends Service {
|
||||
private void setupWidgetUpdater() {
|
||||
if (widgetUpdater == null || widgetUpdater.isCancelled()) {
|
||||
widgetUpdater = new WidgetUpdateWorker();
|
||||
widgetUpdater.execute();
|
||||
if (android.os.Build.VERSION.SDK_INT > android.os.Build.VERSION_CODES.GINGERBREAD_MR1) {
|
||||
widgetUpdater.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
} else {
|
||||
widgetUpdater.execute();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -103,7 +103,7 @@ public class FeedItemMenuHandler {
|
||||
context.startActivity(new Intent(Intent.ACTION_VIEW, uri));
|
||||
break;
|
||||
case R.id.support_item:
|
||||
new FlattrClickWorker(context, selectedItem.getPaymentLink()).execute();
|
||||
new FlattrClickWorker(context, selectedItem.getPaymentLink()).executeAsync();
|
||||
break;
|
||||
case R.id.share_link_item:
|
||||
ShareUtils.shareFeedItemLink(context, selectedItem);
|
||||
|
@ -69,7 +69,7 @@ public class FeedMenuHandler {
|
||||
context.startActivity(new Intent(Intent.ACTION_VIEW, uri));
|
||||
break;
|
||||
case R.id.support_item:
|
||||
new FlattrClickWorker(context, selectedFeed.getPaymentLink()).execute();
|
||||
new FlattrClickWorker(context, selectedFeed.getPaymentLink()).executeAsync();
|
||||
break;
|
||||
case R.id.share_link_item:
|
||||
ShareUtils.shareFeedlink(context, selectedFeed);
|
||||
|
@ -120,7 +120,7 @@ public class FlattrUtils {
|
||||
|
||||
public static void handleCallback(Context context, Uri uri) {
|
||||
AndroidAuthenticator auth = createAuthenticator();
|
||||
new FlattrTokenFetcher(context, auth, uri).execute();
|
||||
new FlattrTokenFetcher(context, auth, uri).executeAsync();
|
||||
}
|
||||
|
||||
public static void revokeAccessToken(Context context) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user