Java 类com.squareup.leakcanary.RefWatcher 实例源码

项目:FastAndroid    文件:BaseApp.java   
@Override
public void onCreate() {
    super.onCreate();
    if (LeakCanary.isInAnalyzerProcess(this)) {
        mRefWatcher = RefWatcher.DISABLED;
    } else {
        mRefWatcher = LeakCanary.install(this);
    }

    if (isInMainProcess()) {
        instance = this;

        Thread.setDefaultUncaughtExceptionHandler(new AppCrashHandler(this));

        initModule();
    }

}
项目:RIBs    文件:SampleApplication.java   
/**
 * Install leak canary for both activities and RIBs.
 */
private void installLeakCanary() {
  final RefWatcher refWatcher = LeakCanary
          .refWatcher(this)
          .watchDelay(2, TimeUnit.SECONDS)
          .buildAndInstall();
  LeakCanary.install(this);
  RibRefWatcher.getInstance().setReferenceWatcher(new RibRefWatcher.ReferenceWatcher() {
    @Override
    public void watch(Object object) {
      refWatcher.watch(object);
    }

    @Override
    public void logBreadcrumb(String eventType, String data, String parent) {
      // Ignore for now. Useful for collecting production analytics.
    }
  });
  RibRefWatcher.getInstance().enableLeakCanary();
}
项目:ClujBike    文件:ClujBikeApp.java   
@Override
public void onCreate() {
    super.onCreate();

    mRefWatcher = LeakCanary.install(this);

    if (mRefWatcher == RefWatcher.DISABLED && "leak".equals(BuildConfig.BUILD_TYPE)) {
        return;
    }

    // build the dependency graph
    mAppComponent = getAppComponentBuilder().build();
    mAppComponent.inject(this);

    Timber.plant(mTimberTree);
}
项目:Tiger-Pro    文件:BaseFragment.java   
@Override
public void onDestroy() {
    if (unbinder != null) {
        unbinder.unbind();
    }
    Fragment fragment = getTargetFragment();
    if (fragment != null && fragment instanceof BaseFragment) {
        BaseFragment targetFragment = (BaseFragment) fragment;
        targetFragment.onFragmentResult(getTargetRequestCode());
    }
    if (mainView != null && mainView.getParent() != null) {
        ((ViewGroup) mainView.getParent()).removeView(mainView);
    }
    super.onDestroy();
    RefWatcher refWatcher = MVPApplication.getRefWatcher(getActivity());
    refWatcher.watch(this);
}
项目:MoonlightNote    文件:MoonlightDetailFragment.java   
@Override
public void onDestroy() {
    if (mInputMethodManager != null) {
        mInputMethodManager.hideSoftInputFromWindow(mActivity.getWindow().getDecorView().getWindowToken(), 0);

    }

    revertUI();

    mAudioPlayer.releasePlayer();
    // remove FragmentOnTouchListener
    if (mFragmentOnTouchListener != null) {
        ((MoonlightActivity) mActivity).unregisterFragmentOnTouchListener(mFragmentOnTouchListener);
    }

    RefWatcher refWatcher = MoonlightApplication.getRefWatcher(mActivity);
    refWatcher.watch(this);
    release();
    super.onDestroy();
}
项目:QuickLyric    文件:LyricsViewFragment.java   
@Override
public void onDestroy() {
    unregisterUpdateBroadcastReceiver();
    threadCancelled = true;
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && networkCallback != null)
        try {
            ((ConnectivityManager) getActivity().getApplicationContext()
                    .getSystemService(Context.CONNECTIVITY_SERVICE)).unregisterNetworkCallback(networkCallback);
        } catch (IllegalArgumentException ignored) {
        }
    if (Build.VERSION.SDK_INT >= 21 && sessionListener != null) {
        ((MediaSessionManager) getActivity().getSystemService(Context.MEDIA_SESSION_SERVICE))
                .removeOnActiveSessionsChangedListener((OnActiveSessionsChangedListener) sessionListener);
    }
    super.onDestroy();
    RefWatcher refWatcher = App.getRefWatcher(getActivity());
    refWatcher.watch(this);
}
项目:GitHub    文件:WEFragment.java   
@Override
public void onDestroy() {
    super.onDestroy();
    RefWatcher watcher = WEApplication.getRefWatcher(getActivity());//使用leakCanary检测fragment的内存泄漏
    if (watcher != null) {
        watcher.watch(this);
    }
    this.mWeApplication =null;
}
项目:EvolvingNetLib    文件:MainActivity.java   
@Override
protected void onDestroy() {
    isDestroyed = true;
    super.onDestroy();

    RefWatcher refWatcher = CCApplication.refWatcher;
    refWatcher.watch(this);
}
项目:yyox    文件:WEFragment.java   
@Override
public void onDestroy() {
    super.onDestroy();
    RefWatcher watcher = WEApplication.getRefWatcher(getActivity());//使用leakCanary检测fragment的内存泄漏
    if (watcher != null) {
        watcher.watch(this);
    }
    this.mWeApplication =null;
}
项目:MVVMFrames    文件:AppConfiguration.java   
@Override
public void injectFragmentLifecycle(Context context, List<FragmentManager.FragmentLifecycleCallbacks> lifecycles) {
    lifecycles.add(new FragmentManager.FragmentLifecycleCallbacks() {
        @Override
        public void onFragmentDestroyed(FragmentManager fm, Fragment f) {
            ((RefWatcher) ((App) f.getActivity().getApplication()).getAppComponent().extras().get(RefWatcher.class.getName())).watch(this);
        }
    });
}
项目:AppCommonFrame    文件:EventBusActivity.java   
@Override
protected void onDestroy() {
    EventBus.getDefault().unregister(this);
    super.onDestroy();
    RefWatcher refWatcher = BaseApp.getRefWatcher(this);
    refWatcher.watch(this);
}
项目:AppCommonFrame    文件:EventBusFragment.java   
@Override
public void onDestroy() {
    EventBus.getDefault().unregister(this);
    super.onDestroy();
    RefWatcher refWatcher = BaseApp.getRefWatcher(getActivity());
    refWatcher.watch(this);
}
项目:AppCommonFrame    文件:BaseFragment.java   
@Override
public void onDestroy() {
    super.onDestroy();
    if(mToast != null)
        mToast.cancel();
    RefWatcher refWatcher = BaseApp.getRefWatcher(getActivity());
    refWatcher.watch(this);
}
项目:MoligyMvpArms    文件:AppLifecyclesImpl.java   
@Override
    public void onCreate(Application application) {
        if (BuildConfig.LOG_DEBUG) {//Timber初始化
            //Timber 是一个日志框架容器,外部使用统一的Api,内部可以动态的切换成任何日志框架(打印策略)进行日志打印
            //并且支持添加多个日志框架(打印策略),做到外部调用一次 Api,内部却可以做到同时使用多个策略
            //比如添加三个策略,一个打印日志,一个将日志保存本地,一个将日志上传服务器
            Timber.plant(new Timber.DebugTree());
            // 如果你想将框架切换为 Logger 来打印日志,请使用下面的代码,如想切换为其他日志框架请根据下面的方式扩展
//                    Logger.addLogAdapter(new AndroidLogAdapter());
//                    Timber.plant(new Timber.DebugTree() {
//                        @Override
//                        protected void log(int priority, String tag, String message, Throwable t) {
//                            Logger.log(priority, tag, message, t);
//                        }
//                    });
            ButterKnife.setDebug(true);
        }
        //leakCanary内存泄露检查
        ArmsUtils.obtainAppComponentFromContext(application).extras().put(RefWatcher.class.getName(), BuildConfig.USE_CANARY ? LeakCanary.install(application) : RefWatcher.DISABLED);
        //扩展 AppManager 的远程遥控功能
        ArmsUtils.obtainAppComponentFromContext(application).appManager().setHandleListener((appManager, message) -> {
            switch (message.what) {
                //case 0:
                //do something ...
                //   break;
            }
        });
        //Usage:
        //Message msg = new Message();
        //msg.what = 0;
        //AppManager.post(msg); like EventBus
    }
项目:MyAnimeViewer    文件:BaseFragment.java   
@Override
public void onDestroy() {
    super.onDestroy();

    RefWatcher refWatcher = MAVApplication.getRefWatcher(getActivity());
    refWatcher.watch(this);
}
项目:PicShow-zhaipin    文件:WEFragment.java   
@Override
public void onDestroy() {
    super.onDestroy();
    RefWatcher watcher = WEApplication.getRefWatcher(getActivity());//使用leakCanary检测fragment的内存泄漏
    if (watcher != null) {
        watcher.watch(this);
    }
    this.mWeApplication =null;
}
项目:ApplicationCollention    文件:BaseActivity.java   
@Override
protected void onDestroy() {
    super.onDestroy();
    //销毁Activity时,检测内存泄露
    RefWatcher refWatcher = MyApplication.getRefWatcher(this);
    refWatcher.watch(this);
    if (presenter != null) {
        presenter.detachView();
    }
}
项目:boohee_v5.6    文件:BaseDialogFragment.java   
public void onDestroy() {
    super.onDestroy();
    RefWatcher refWatcher = MyApplication.getRefWatcher(getActivity());
    if (refWatcher != null) {
        refWatcher.watch(this);
    }
    RequestManager.cancelAll(this);
}
项目:boohee_v5.6    文件:BaseFragment.java   
public void onDestroy() {
    super.onDestroy();
    RefWatcher refWatcher = MyApplication.getRefWatcher(getActivity());
    if (refWatcher != null) {
        refWatcher.watch(this);
    }
    RequestManager.cancelAll(this);
}
项目:mvparms    文件:WEFragment.java   
@Override
public void onDestroy() {
    super.onDestroy();
    RefWatcher watcher = WEApplication.getRefWatcher(getActivity());//使用leakCanary检测fragment的内存泄漏
    if (watcher != null) {
        watcher.watch(this);
    }
    this.mWeApplication = null;
}
项目:AndZilla    文件:MainActivity.java   
@Override
protected void onDestroy() {
    permission.recycle();
    super.onDestroy();
    RefWatcher refWatcher = AndZillaApplication.getRefWatcher(this);
    refWatcher.watch(this);
}
项目:GmArchMvvm    文件:AppLifecyclesImpl.java   
@Override
public void onCreate(Application application) {
    if (LeakCanary.isInAnalyzerProcess(application)) {
        // This process is dedicated to LeakCanary for heap analysis.
        // You should not init your app in this process.
        return;
    }
    if (BuildConfig.LOG_DEBUG) {
        //Timber is initialized
        //Timber is a log frame container, the external use of a unified Api, the internal can be dynamically switched to any log frame (print strategy) for log printing
        //And support the addition of multiple log framework (print strategy), so that an external call Api, the internal can do at the same time using multiple strategies
        //Such as adding three strategies, a print log, a log to save the local, a log upload server
        Timber.plant(new Timber.DebugTree());
        // If you want to switch the frame to Logger to print the log, use the following code, if you want to switch to another log frame, expand as follows
        //                    Logger.addLogAdapter(new AndroidLogAdapter());
        //                    Timber.plant(new Timber.DebugTree() {
        //                        @Override
        //                        protected void log(int priority, String tag, String message, Throwable t) {
        //                            Logger.log(priority, tag, message, t);
        //                        }
        //                    });
    }
    //leakCanary memory leak check
    RepositoryUtils.INSTANCE.obtainRepositoryComponent(application)
            .extras()
            .put(RefWatcher.class.getName(), BuildConfig.USE_CANARY ? LeakCanary.install(application) : RefWatcher.DISABLED);

    //Set the global Crash monitor
    CrashUtils.init(application, RepositoryUtils.INSTANCE.obtainRepositoryComponent(application).cacheFile());

    //Extended AppManager remote control function
    LifecycleUtils.INSTANCE.obtainLifecycleComponent(application).appManager()
            .setHandleListener((appManager, message) -> {
                Timber.d("handleMessage: " + message.what);
                //AppManager.post(message);
                //handle message
            });
}
项目:VanGogh    文件:BaseApplication.java   
/**
 * 内存泄漏检测
 *
 * @param context
 * @return
 */
public static RefWatcher getRefWatcher(Context context) {
    BaseApplication application = (BaseApplication) context.getApplicationContext();

    if (AppUtils.isDebug(application.getApplicationContext(), AppUtils.getPackageName(application.getApplicationContext()))) {
        return application.refWatcher;
    }
    //内存泄漏检测, 发版时改为此配置
    return RefWatcher.DISABLED;
}
项目:MVPArmsTest1    文件:GlobalConfiguration.java   
@Override
public void injectFragmentLifecycle(Context context, List<FragmentManager.FragmentLifecycleCallbacks> lifecycles) {
    lifecycles.add(new FragmentManager.FragmentLifecycleCallbacks() {
        @Override
        public void onFragmentDestroyed(FragmentManager fm, Fragment f) {
            ((RefWatcher) ((App) f.getActivity().getApplication()).getAppComponent().extras().get(RefWatcher.class.getName())).watch(this);
        }
    });
}
项目:MVVMArms    文件:AppLifecyclesImpl.java   
@Override
public void onCreate(Application application) {
    if (LeakCanary.isInAnalyzerProcess(application)) {
        // This process is dedicated to LeakCanary for heap analysis.
        // You should not init your app in this process.
        return;
    }
    if (BuildConfig.LOG_DEBUG) {
        /* Timber 是一个日志框架容器,外部使用统一的Api,内部可以动态的切换成任何日志框架(打印策略)进行日志打印
        并且支持添加多个日志框架(打印策略),做到外部调用一次 Api,内部却可以做到同时使用多个策略
        比如添加三个策略,一个打印日志,一个将日志保存本地,一个将日志上传服务器 */
        //Timber初始化
        Timber.plant(new Timber.DebugTree());
        /* 如果你想将框架切换为 Logger 来打印日志,请使用下面的代码,如想切换为其他日志框架请根据下面的方式扩展
        Logger.addLogAdapter(new AndroidLogAdapter());
        Timber.plant(new Timber.DebugTree() {
            @Override
            protected void log(int priority, String tag, String message, Throwable t) {
                Logger.log(priority, tag, message, t);
            }
        }); */
    }

    //LeakCanary内存泄露检查
    RepositoryUtils.INSTANCE.obtainRepositoryComponent(application)
            .extras()
            .put(RefWatcher.class.getName(), BuildConfig.USE_CANARY ? LeakCanary.install(application) : RefWatcher.DISABLED);

    //设置全局Crash监听
    CrashUtils.init(application, RepositoryUtils.INSTANCE.obtainRepositoryComponent(application).cacheFile());

    //扩展 AppManager 的远程遥控功能
    LifecycleUtils.INSTANCE.obtainLifecycleComponent(application).appManager()
            .setHandleListener((appManager, message) -> {
                Timber.d("handleMessage: " + message.what);
                //AppManager.post(message);
                //handle message
            });
}
项目:LiteSDK    文件:BaseFragment.java   
@Override
public void onAttach(Activity activity) {
    super.onAttach(activity);
    eventBus.register(this);
    if (BuildConfig.DEBUG) {
        RefWatcher refWatcher = AndroidApplication.getRefWatcher(getActivity());
        refWatcher.watch(this);
    }
}
项目:MarkdownEditors    文件:BaseApplication.java   
public static RefWatcher getRefWatcher(Context context) {
    if (context == null) {
        return null;
    }
    BaseApplication application = (BaseApplication) context.getApplicationContext();
    if (application.hasMemoryLeak()) {
        return application.refWatcher;
    }
    return null;
}
项目:MarkdownEditors    文件:BaseFragment.java   
@Override
public void onDestroy() {
    super.onDestroy();
    if (BuildConfig.DEBUG) {//Debug的时候检查内存泄露
        RefWatcher refWatcher = BaseApplication.getRefWatcher(mContext);
        if (refWatcher != null) {
            refWatcher.watch(this);
        }
    }
}
项目:instantsearch-android-examples    文件:EcommerceActivity.java   
@Override
protected void onDestroy() {
    filterResultsWindow.dismiss();
    searcher.destroy();
    toggleArrow(buttonFilter, false);
    super.onDestroy();
    RefWatcher refWatcher = EcommerceApplication.getRefWatcher(this);
    refWatcher.watch(this);
    refWatcher.watch(findViewById(R.id.hits));
}
项目:science-journal    文件:ManageDevicesRecyclerFragment.java   
@Override
public void onDestroy() {
    stopScanning();
    mMainMenu = null;
    mMyDevices.onDestroy();
    mMyDevices = null;
    super.onDestroy();

    // Make sure we don't leak this fragment.
    RefWatcher watcher = WhistlePunkApplication.getRefWatcher(getActivity());
    watcher.watch(this);
}
项目:Codementor    文件:App.java   
public RefWatcher getRefWatcher() {
    if (refWatcher == null) {
        refWatcher = LeakCanary.install(this);
    }

    return refWatcher;
}
项目:dontsuck-mp    文件:DontSuckMp.java   
@CheckResult @NonNull public static RefWatcher getRefWatcher(@NonNull Fragment fragment) {
  final Application application = fragment.getActivity().getApplication();
  if (application instanceof DontSuckMp) {
    return ((DontSuckMp) application).getRefWatcher();
  } else {
    throw new IllegalStateException("Application is not DontSuckMp");
  }
}
项目:MVPFrames    文件:AppConfiguration.java   
@Override
public void injectFragmentLifecycle(Context context, List<FragmentManager.FragmentLifecycleCallbacks> lifecycles) {
    lifecycles.add(new FragmentManager.FragmentLifecycleCallbacks() {
        @Override
        public void onFragmentDestroyed(FragmentManager fm, Fragment f) {
            ((RefWatcher) ((App) f.getActivity().getApplication()).getAppComponent().extras().get(RefWatcher.class.getName())).watch(this);
        }
    });
}
项目:Tiger-Pro    文件:BaseActivity.java   
@Override
protected void onDestroy() {
    unbinder.unbind();
    super.onDestroy();
    fixInputMethodManagerLeak(this);
    RefWatcher refWatcher = MVPApplication.getRefWatcher(this);
    refWatcher.watch(this);
}
项目:MoonlightNote    文件:MoonlightListFragment.java   
@Override
public void onDestroy() {
    super.onDestroy();
    if (mFirebaseRecyclerAdapter != null) {
        Log.d(TAG, "cleanup");
        mFirebaseRecyclerAdapter.cleanup();
    }

    RefWatcher refWatcher = MoonlightApplication.getRefWatcher(mActivity);
    refWatcher.watch(this);
}
项目:MVP-Boilerplate    文件:DebugApp.java   
private void initializeLeakCanary() {
    if (LeakCanary.isInAnalyzerProcess(getApplicationContext())) {
        // This process is dedicated to LeakCanary for heap analysis.
        // You should not init your app in this process.
        mRefWatcher = RefWatcher.DISABLED;
    } else {
        // Ignore known Android SDK leaks
        ExcludedRefs excludedRefs = AndroidExcludedRefs.createAppDefaults()
                .build();

        mRefWatcher = LeakCanary.refWatcher(getApplicationContext())
                .excludedRefs(excludedRefs)
                .buildAndInstall();
    }
}
项目:S1-Next    文件:LeaksUtil.java   
public static RefWatcher install(Application application) {
    if (BuildConfig.DEBUG) {
        ExcludedRefs excludedRefs = AndroidExcludedRefs.createAppDefaults()
                //exclude InputMethodManager
                .clazz("android.view.inputmethod.InputMethodManager")
                .build();
        return LeakCanary.refWatcher(application)
                .listenerServiceClass(DisplayLeakService.class)
                .excludedRefs(excludedRefs)
                .buildAndInstall();
    } else {
        return LeakCanary.install(application);
    }
}
项目:S1-Next    文件:BaseFragment.java   
@Override
public void onDestroy() {
    super.onDestroy();

    RefWatcher refWatcher = App.get().getRefWatcher();
    refWatcher.watch(this);
}
项目:aibao_demo    文件:AbsFragment.java   
@Override
public void onDestroy() {
    dialogDismiss();
    super.onDestroy();
    if (BuildConfig.CANARY_DEBUG) {
        RefWatcher refWatcher = App.getRefWatcher(getActivity());
        refWatcher.watch(this);
    }
}
项目:MVPArms    文件:AppLifecyclesImpl.java   
@Override
    public void onCreate(Application application) {
        if (LeakCanary.isInAnalyzerProcess(application)) {
            // This process is dedicated to LeakCanary for heap analysis.
            // You should not init your app in this process.
            return;
        }
        if (BuildConfig.LOG_DEBUG) {//Timber初始化
            //Timber 是一个日志框架容器,外部使用统一的Api,内部可以动态的切换成任何日志框架(打印策略)进行日志打印
            //并且支持添加多个日志框架(打印策略),做到外部调用一次 Api,内部却可以做到同时使用多个策略
            //比如添加三个策略,一个打印日志,一个将日志保存本地,一个将日志上传服务器
            Timber.plant(new Timber.DebugTree());
            // 如果你想将框架切换为 Logger 来打印日志,请使用下面的代码,如想切换为其他日志框架请根据下面的方式扩展
//                    Logger.addLogAdapter(new AndroidLogAdapter());
//                    Timber.plant(new Timber.DebugTree() {
//                        @Override
//                        protected void log(int priority, String tag, String message, Throwable t) {
//                            Logger.log(priority, tag, message, t);
//                        }
//                    });
            ButterKnife.setDebug(true);
        }
        //leakCanary内存泄露检查
        ArmsUtils.obtainAppComponentFromContext(application).extras().put(RefWatcher.class.getName(), BuildConfig.USE_CANARY ? LeakCanary.install(application) : RefWatcher.DISABLED);
        //扩展 AppManager 的远程遥控功能
        ArmsUtils.obtainAppComponentFromContext(application).appManager().setHandleListener((appManager, message) -> {
            switch (message.what) {
                //case 0:
                //do something ...
                //   break;
            }
        });
        //Usage:
        //Message msg = new Message();
        //msg.what = 0;
        //AppManager.post(msg); like EventBus
    }