private void onLoadRemainingCounter() { AsyncTask<String, Void, int[]> task = new AsyncTask<String, Void, int[]>() { @Override protected int[] doInBackground(String... params) { if (isCancelled()) { return null; } int[] counts = new int[2]; counts[0] = DBUtils.getUnwatchedEpisodesOfShow(getActivity(), params[0]); counts[1] = DBUtils.getUncollectedEpisodesOfShow(getActivity(), params[0]); return counts; } @Override protected void onPostExecute(int[] result) { if (isAdded()) { if (mTextViewRemaining != null) { if (result[0] == -1) { mTextViewRemaining.setText( getString(R.string.remaining, getString(R.string.norating))); } else if (result[0] == 0) { mTextViewRemaining.setText(null); } else { mTextViewRemaining.setText(getString(R.string.remaining, result[0])); } } if (mButtonWatchedAll != null) { setWatchedToggleState(result[0]); } if (mButtonCollectedAll != null) { setCollectedToggleState(result[1]); } } } }; AndroidUtils.executeOnPool(task, String.valueOf(getShowId())); }