@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(); } }
/** * 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(); }
@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); }
@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); }
@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(); }
@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); }
@Override public void onDestroy() { super.onDestroy(); RefWatcher watcher = WEApplication.getRefWatcher(getActivity());//使用leakCanary检测fragment的内存泄漏 if (watcher != null) { watcher.watch(this); } this.mWeApplication =null; }
@Override protected void onDestroy() { isDestroyed = true; super.onDestroy(); RefWatcher refWatcher = CCApplication.refWatcher; refWatcher.watch(this); }
@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); } }); }
@Override protected void onDestroy() { EventBus.getDefault().unregister(this); super.onDestroy(); RefWatcher refWatcher = BaseApp.getRefWatcher(this); refWatcher.watch(this); }
@Override public void onDestroy() { EventBus.getDefault().unregister(this); super.onDestroy(); RefWatcher refWatcher = BaseApp.getRefWatcher(getActivity()); refWatcher.watch(this); }
@Override public void onDestroy() { super.onDestroy(); if(mToast != null) mToast.cancel(); RefWatcher refWatcher = BaseApp.getRefWatcher(getActivity()); refWatcher.watch(this); }
@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 }
@Override public void onDestroy() { super.onDestroy(); RefWatcher refWatcher = MAVApplication.getRefWatcher(getActivity()); refWatcher.watch(this); }
@Override protected void onDestroy() { super.onDestroy(); //销毁Activity时,检测内存泄露 RefWatcher refWatcher = MyApplication.getRefWatcher(this); refWatcher.watch(this); if (presenter != null) { presenter.detachView(); } }
public void onDestroy() { super.onDestroy(); RefWatcher refWatcher = MyApplication.getRefWatcher(getActivity()); if (refWatcher != null) { refWatcher.watch(this); } RequestManager.cancelAll(this); }
@Override public void onDestroy() { super.onDestroy(); RefWatcher watcher = WEApplication.getRefWatcher(getActivity());//使用leakCanary检测fragment的内存泄漏 if (watcher != null) { watcher.watch(this); } this.mWeApplication = null; }
@Override protected void onDestroy() { permission.recycle(); super.onDestroy(); RefWatcher refWatcher = AndZillaApplication.getRefWatcher(this); refWatcher.watch(this); }
@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 }); }
/** * 内存泄漏检测 * * @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; }
@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 }); }
@Override public void onAttach(Activity activity) { super.onAttach(activity); eventBus.register(this); if (BuildConfig.DEBUG) { RefWatcher refWatcher = AndroidApplication.getRefWatcher(getActivity()); refWatcher.watch(this); } }
public static RefWatcher getRefWatcher(Context context) { if (context == null) { return null; } BaseApplication application = (BaseApplication) context.getApplicationContext(); if (application.hasMemoryLeak()) { return application.refWatcher; } return null; }
@Override public void onDestroy() { super.onDestroy(); if (BuildConfig.DEBUG) {//Debug的时候检查内存泄露 RefWatcher refWatcher = BaseApplication.getRefWatcher(mContext); if (refWatcher != null) { refWatcher.watch(this); } } }
@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)); }
@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); }
public RefWatcher getRefWatcher() { if (refWatcher == null) { refWatcher = LeakCanary.install(this); } return refWatcher; }
@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"); } }
@Override protected void onDestroy() { unbinder.unbind(); super.onDestroy(); fixInputMethodManagerLeak(this); RefWatcher refWatcher = MVPApplication.getRefWatcher(this); refWatcher.watch(this); }
@Override public void onDestroy() { super.onDestroy(); if (mFirebaseRecyclerAdapter != null) { Log.d(TAG, "cleanup"); mFirebaseRecyclerAdapter.cleanup(); } RefWatcher refWatcher = MoonlightApplication.getRefWatcher(mActivity); refWatcher.watch(this); }
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(); } }
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); } }
@Override public void onDestroy() { super.onDestroy(); RefWatcher refWatcher = App.get().getRefWatcher(); refWatcher.watch(this); }
@Override public void onDestroy() { dialogDismiss(); super.onDestroy(); if (BuildConfig.CANARY_DEBUG) { RefWatcher refWatcher = App.getRefWatcher(getActivity()); refWatcher.watch(this); } }
@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 }