抱歉我的英文。 在其应用程序中,我使用Android Image Slider https://github.com/daimajia/AndroidImageSlider
这里是代码:
SliderLayout exPhoto = (SliderLayout) findViewById(R.id.ex_img);
exPhoto.removeAllSliders();
for (String url : object.getImages()) {
try {
Log.e("test", "load textSliderView");
TextSliderView textSliderView = new TextSliderView(this);
textSliderView
.image(url)
.setScaleType(BaseSliderView.ScaleType.CenterCrop);
exPhoto.addSlider(textSliderView);
}catch (OutOfMemoryError e){
Log.e("test", "exception textSliderView");
}
}
exPhoto.stopAutoCycle();
这里的错误:
05-11 15:41:08.855 5873-6125/ru.mabee.justme_android.app E/Bitmap? createBitmap error!
05-11 15:41:09.335 5873-6126/ru.mabee.justme_android.app E/dalvikvm? GC_FOR_ALLOC freed 1674K, 18% free 53549K/64995K, paused 4ms+22ms
05-11 15:41:09.445 5873-5873/ru.mabee.justme_android.app E/AndroidRuntime? FATAL EXCEPTION: main
java.lang.OutOfMemoryError
at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:492)
at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:360)
at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:773)
at android.content.res.Resources.loadDrawable(Resources.java:1937)
at android.content.res.Resources.getDrawable(Resources.java:664)
at android.widget.ImageView.resolveUri(ImageView.java:542)
at android.widget.ImageView.setImageResource(ImageView.java:315)
at com.squareup.picasso.ImageViewAction.error(ImageViewAction.java:61)
at com.squareup.picasso.Picasso.deliverAction(Picasso.java:563)
at com.squareup.picasso.Picasso.complete(Picasso.java:510)
at com.squareup.picasso.Picasso$1.handleMessage(Picasso.java:117)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4424)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:554)
at dalvik.system.NativeStart.main(Native Method)
E/dalvikvm? GC_FOR_ALLOC freed 395K, 17% free 54464K/64995K, paused 2ms+18ms
E/dalvikvm? GC_BEFORE_OOM freed 105K, 17% free 54358K/64995K, paused 170ms
E/dalvikvm-heap? Out of memory on a 983056-byte allocation.
我所能做的就是将路径传递给图像
textSliderView
.image(url)
.setScaleType(BaseSliderView.ScaleType.CenterCrop);
我不直接使用Bitmaps
低手机和20次更新后会出现此错误。
请,帮助
答案 0 :(得分:0)
我猜你应该做exPhoto.stopAutoCycle();在你的活动的onStop或片段的onDestroyView中,不是在创建视图之后,这在你的lib的例子中描述
@Override
protected void onStop() {
// To prevent a memory leak on rotation, make sure to call stopAutoCycle() on the slider before activity or fragment is destroyed
mDemoSlider.stopAutoCycle();
super.onStop();
}
如果这无济于事,请尝试弄清楚其他地方是否有内存泄漏