zoukankan      html  css  js  c++  java
  • android 之 下载管理器 无论监测在当地的设计思路

    我相信你。让应用市场。或其它下载,想不管是什么地方监测进展情况。而且很好的实现。

    这里分享一个相对简单的,并防止内存溢出等。。我们用一个引用弱结合View进展更新方法。

    Map<String, WeakReference<View>> viewListem = new HashMap<String, WeakReference<View>>();// 对进度条进行弱引用

    防止内存不够的时候进行回收。

    key为下载地址

    value 进度条

    //加入进度条引用。

    public synchronized void addViewToCache(String path, View view) {

    if (viewListem == null) {
    return;
    }
    WeakReference<View> softView = new WeakReference<View>(view);
    viewListem.put(path, softView);
    }
    //获取进度条。
    public synchronized View getViewByPath(String path) {
    if (viewListem == null) {
    return null;
    }
    // 从缓存中取软引用的View对象
    WeakReference<View> softView = viewListem.get(path);
    // 推断是否存在软引用
    if (softView == null) {
    return null;
    }
    // 取出View对象,假设因为内存不足View被回收,将取得空
    View view= softView.get();
    return view;
    }


    接下来就是,就到进度监听的回调接口去。获取到相应的View更新进度条。弄。

    不是一个简单的,容易实现。但也要防止内存溢出。

    版权声明:本文博主原创文章。博客,未经同意不得转载。

  • 相关阅读:
    1370
    1336
    1298
    1289
    Buy Tickets(poj2828)
    The Balance(poj2142)
    1067
    Lightoj1011
    1319
    Back to Underworld(lightoj 1009)
  • 原文地址:https://www.cnblogs.com/bhlsheji/p/4826060.html
Copyright © 2011-2022 走看看