避免从Android回收位图

我有两个asynchronous任务之一,其中一个下载图像,另一个添加模糊效果,但我的问题是,在onPostExecutecallback的下载任务我想把位图在一个ImageView中,然后传递给第二个任务运用模糊效果,但有时我得到

 trying to use a recycled bitmap 

我已经search了很多关于这个问题,但我没有find一个明确的解决scheme,以避免这个问题,特别是我使用这个图像在一个视图的分页器这是我的代码

  protected void onPostExecute(Bitmap result) { Bitmap bitmap=result; bmImage.setImageBitmap(bitmap); if(bitmap!=null && !bitmap.isRecycled()){ Bitmap bb=bitmap; new blurTask().execute(bb);} } 

这是我的完整的片段代码

 public class ScreenSlidePageFragment extends Fragment { int page; String img; // ImageView blured; String[] checkblur; int size; Boolean onCreateViewCalled = false; ImageView blur; ImageView imageView; public static ScreenSlidePageFragment newInstance(int page, String img, int size) { ScreenSlidePageFragment fragmentFirst = new ScreenSlidePageFragment(); Bundle args = new Bundle(); args.putInt("someInt", page); args.putString("img", img); args.putInt("size", size); fragmentFirst.setArguments(args); return fragmentFirst; } // Store instance variables based on arguments passed @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); page = getArguments().getInt("someInt", 0); img = getArguments().getString("img"); size = getArguments().getInt("size"); checkblur = new String[size]; onCreateViewCalled = false; } public void ChangeAlpha(float alpha) { System.out.println(alpha); blur.setAlpha(alpha); } @Override public void onViewCreated(View view, Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); } @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View v = (View) inflater.inflate( R.layout.fragment_screen_slide_page, container, false); imageView = (ImageView) v.findViewById(R.id.image); blur = (ImageView) v.findViewById(R.id.blur); //Glide.with(this).load(img).into(imageView); new DownloadImageTask(imageView).execute(img); return v; } class blurTask extends AsyncTask<Bitmap, Integer, BitmapDrawable> { Bitmap image; @Override protected void onPreExecute() { super.onPreExecute(); } @Override protected BitmapDrawable doInBackground(Bitmap... params) { image = params[0]; Bitmap b = Blur.blurBitmap(image, getActivity()); final BitmapDrawable ob = new BitmapDrawable(getResources(), b); return ob; } @Override protected void onPostExecute(BitmapDrawable blur1) { // Do whatever you need with the string, you can update your UI from here // blured.setBackground(blur); if (blur1 != null) System.out.println("yryryryry"); blur.setBackground(blur1); } } class DownloadImageTask extends AsyncTask<String, Void, Bitmap> { ImageView bmImage; public DownloadImageTask(ImageView bmImage) { this.bmImage = bmImage; } protected Bitmap doInBackground(String... urls) { String urldisplay = urls[0]; Bitmap mIcon11 = null; try { InputStream in = new java.net.URL(urldisplay).openStream(); mIcon11 = BitmapFactory.decodeStream(in); } catch (Exception e) { Log.e("Error", e.getMessage()); e.printStackTrace(); } return mIcon11; } protected void onPostExecute(Bitmap result) { bmImage.setImageBitmap(Bitmap.createBitmap(result)); new blurTask().execute(Bitmap.createBitmap(bmImage)); } } } 

所以我得到的图像,然后模糊效果出现,但是当我尝试滑动到下一个viewpager页面,我得到这个错误
任何帮助?
谢谢。

Solutions Collecting From Web of "避免从Android回收位图"