Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AutoLoopTask 优化下? #1235

Open
lianyagang opened this issue Jul 15, 2024 · 1 comment
Open

AutoLoopTask 优化下? #1235

lianyagang opened this issue Jul 15, 2024 · 1 comment

Comments

@lianyagang
Copy link

static class AutoLoopTask implements Runnable {
private final WeakReference reference;

    AutoLoopTask(Banner banner) {
        this.reference = new WeakReference<>(banner);
    }

    @Override
    public void run() {
        Banner banner = reference.get();
        if (banner != null && banner.mIsAutoLoop) {
            int count = banner.getItemCount();
            if (count == 0) {
                return;
            }
            int next = (banner.getCurrentItem() + 1) % count;
            banner.setCurrentItem(next);
            banner.postDelayed(banner.mLoopTask, banner.mLoopTime);
        }
    }
}

建议添加一下,如果有且只有一条数据,就不要再发送postDelayed了

@gebaobao
Copy link

gebaobao commented Sep 2, 2024

这里最大的问题是,需要在执行postDelayed()前
banner.removeCallbacks(banner.mLoopTask);
不然低性能的设备上会出现单次连续执行任务

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants