Comments (14)
我试了试在onPause里调用pauseScroll就没有内存泄露了,onResume里start。轮播的线程占用了context,activity退出时主动停止就行。
from flycobanner_master.
这样子可以解决内存泄露,在onDetachedFromWindow()中结束线程
···
public class SimpleImageBanner extends BaseIndicaorBanner<Course, SimpleImageBanner> {
public SimpleImageBanner(Context context) {
this(context, null, 0);
}
public SimpleImageBanner(Context context, AttributeSet attrs) {
this(context, attrs, 0);
}
public SimpleImageBanner(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
@Override
public void onTitleSlect(TextView tv, int position) {
}
@Override
public View onCreateItemView(int position) {
Course data = list.get(position);
ImageView imageView = new ImageView(context);
int itemWidth = dm.widthPixels;
int itemHeight = (int) (itemWidth * 430 * 1.0f / 1080);
imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
// imageView.setLayoutParams(new LinearLayoutCompat.LayoutParams(itemWidth,itemHeight));
imageView.setLayoutParams(new LinearLayout.LayoutParams(itemWidth,itemHeight));
Picasso.with(context).load(data.getImg_src()).into(imageView);
return imageView;
}
@Override
protected void onDetachedFromWindow() {
pauseScroll();
super.onDetachedFromWindow();
}
···
from flycobanner_master.
在onResume中应该使用goOnScroll()要不然报错
from flycobanner_master.
麻烦把问题说清楚!我也在用,描述出来才能修改!
from flycobanner_master.
确实有内存泄露,轮播的线程池应该持有当前界面的context
from flycobanner_master.
你们是如何解决的?我也碰到了内存泄漏问题
from flycobanner_master.
非常感谢你的回答,谢谢你。
from flycobanner_master.
哦,好的,我这暂时木有发现问题呢,哈哈,多谢你的提醒。
from flycobanner_master.
多谢大神们分析解决!
from flycobanner_master.
在onDetachedFromWindo()里应该加一个是正在滑动的判断再pauseScroll()可能会好些吧?
from flycobanner_master.
但是你停止了,还需要再次启动。。
@OverRide
public void onResume() {
super.onResume();
convenientBanner.goOnScroll();
}
from flycobanner_master.
@ysmintor 没有必要。就是一个轮询线程。看看源码
from flycobanner_master.
@lucheng0522 对。普通的view你在activity或者fragmet中可以拿到它的引用,在合适的生命周期,开始滚动和停止滚动,是不会出现内存泄露的。但是有时候这个view必须在adapter中直接new出来,就不能通过activity的生命周期控制,只能用View的onDetachedFromWindow()的时候shutdwn这个线程。在我自己的项目中遇到这个问题了,经过实际测试,可以解决内存泄露。
from flycobanner_master.
我把作者的线程来定时轮播,改成直接使用Handler来处理了,参见:BaseBanner
from flycobanner_master.
Related Issues (20)
- 这个库性能有点问题,不建议直接使用
- 在代码中设置控制是否自动轮播无效 HOT 5
- Show layout
- 引导页的最后一页如何实现滑动跳转 HOT 1
- 图片显示不全 HOT 1
- 刷新问题 请教lz HOT 2
- DEMO SimpleImageBanner 中onCreateItemView方法 HOT 2
- 内存泄露问题 HOT 2
- How to set the indicator's distance from the bottom HOT 2
- In case of just one image
- 只有一张图也会轮播,这个体验不好,希望支持只有一张轮播图时,默认不轮播,轮播点也不显示。 HOT 1
- The application's PagerAdapter changed the adapter's contents without calling PagerAdapter#notifyDataSetChan HOT 1
- Caused by: java.lang.ArithmeticException: divide by zero
- 加载之前的黑屏 HOT 1
- 跳转SimpleGuideBanner界面时会出现一闪而过的空白。demo中也是
- 设置图片的高度,下面直接留白
- 请问下这个和fragment一起怎么使用? HOT 1
- 触摸崩溃
- 怎么刷新啊
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from flycobanner_master.