Java Code Examples for com.squareup.leakcanary.RefWatcher#watch()

The following examples show how to use com.squareup.leakcanary.RefWatcher#watch() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MimiFragmentBase.java    From mimi-reader with Apache License 2.0 6 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    if (getArguments() != null) {
        Bundle extras = getArguments();

        boolean hasOptionsMenu = extras.getBoolean(Extras.EXTRAS_OPTIONS_MENU_ENABLED, true);
        setHasOptionsMenu(hasOptionsMenu);
    } else {
        setHasOptionsMenu(true);
    }

    RefWatcher refWatcher = MimiApplication.getInstance().getRefWatcher();
    if (refWatcher != null) {
        refWatcher.watch(this);
    }

}
 
Example 2
Source File: LyricsViewFragment.java    From QuickLyric with GNU General Public License v3.0 6 votes vote down vote up
@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);
}
 
Example 3
Source File: BaseActivity.java    From BlueBoard with Apache License 2.0 5 votes vote down vote up
@Override
protected void onDestroy() {
    super.onDestroy();
    RefWatcher refWatcher = MyApplication.getRefWatcher(this);
    refWatcher.watch(this);
    mCompositeSubscription.unsubscribe();
}
 
Example 4
Source File: LeakActivity.java    From XKnife-Android with Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_leak);

    // ①使用 RefWatcher 监控 Activity
    RefWatcher refWatcher = AppApplication.getRefWatcher(this);
    refWatcher.watch(this);

    // ② LeakSingleton
    TextView text = (TextView) findViewById(R.id.tv);
    LeakSingleton.getInstance(this.getApplication()).setRetainedTextView(text);

    // ③
    View button = findViewById(R.id.btn);
    button.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            startAsyncTask();
        }
    });

    // ④ LeakHandler (Wrong)
    leakyHandler.postDelayed(new Runnable() {
        @Override
        public void run() {
            // 原因: 当前Activity finish后,延迟执行任务的Message还会继续存在于主线程中,它持有LeakActivity造成其无法回收而内存泄漏
        }
    }, 1000 * 60 * 1);

    // ④ LeakHandler (Right)
    notLeakHandler.postDelayed(sRunnable, 1000 * 60 * 1);
}
 
Example 5
Source File: ActivityBaseInternal.java    From AcDisplay with GNU General Public License v2.0 5 votes vote down vote up
void onDestroy() {
    mCheckout = null;
    if (mInputMethodResetRequest) performInputMethodServiceReset();
    // Watch for the activity to detect possible leaks.
    RefWatcher refWatcher = AppHeap.getRefWatcher();
    refWatcher.watch(this);
}
 
Example 6
Source File: ManageDevicesRecyclerFragment.java    From science-journal with Apache License 2.0 5 votes vote down vote up
@Override
public void onDestroy() {
  stopScanning();
  mainMenu = null;
  myDevices.onDestroy();
  myDevices = null;
  super.onDestroy();

  // Make sure we don't leak this fragment.
  RefWatcher watcher = WhistlePunkApplication.getAppServices(getActivity()).getRefWatcher();
  watcher.watch(this);
}
 
Example 7
Source File: BaseFragment.java    From Loop with Apache License 2.0 5 votes vote down vote up
@Override
public void onDestroy() {
    super.onDestroy();

    RefWatcher refWatcher = LoopApplication.getRefWatcher(getActivity());
    refWatcher.watch(this);
}
 
Example 8
Source File: SearchFragment.java    From QuickLyric with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onDestroy() {
    ((SearchPagerAdapter) ((SearchActivity) getActivity()).getViewPager().getAdapter()).removeFragment(this);
    super.onDestroy();
    RefWatcher refWatcher = App.getRefWatcher(getActivity());
    refWatcher.watch(this);
}
 
Example 9
Source File: RecentTracksFragment.java    From QuickLyric with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onDestroy() {
    RefWatcher refWatcher = App.getRefWatcher(getActivity());
    refWatcher.watch(this);
    EventBus.getDefault().unregister(this);
    super.onDestroy();

}
 
Example 10
Source File: MetricsFragment.java    From hawkular-android-client with Apache License 2.0 4 votes vote down vote up
private void detectLeaks() {
    RefWatcher refWatcher = HawkularApplication.getRefWatcher(getActivity());
    refWatcher.watch(this);
}
 
Example 11
Source File: BaseFragment.java    From BlueBoard with Apache License 2.0 4 votes vote down vote up
@Override
public void onDestroyView() {
    super.onDestroyView();
    RefWatcher refWatcher = MyApplication.getRefWatcher(getActivity());
    refWatcher.watch(this);
}
 
Example 12
Source File: TriggersFragment.java    From hawkular-android-client with Apache License 2.0 4 votes vote down vote up
private void detectLeaks() {
    RefWatcher refWatcher = HawkularApplication.getRefWatcher(getActivity());
    refWatcher.watch(this);
}
 
Example 13
Source File: FavMetricsFragment.java    From hawkular-android-client with Apache License 2.0 4 votes vote down vote up
private void detectLeaks() {
    RefWatcher refWatcher = HawkularApplication.getRefWatcher(getActivity());
    refWatcher.watch(this);
}
 
Example 14
Source File: TriggerDetailFragment.java    From hawkular-android-client with Apache License 2.0 4 votes vote down vote up
private void detectLeaks() {
    RefWatcher refWatcher = HawkularApplication.getRefWatcher(getActivity());
    refWatcher.watch(this);
}
 
Example 15
Source File: MetricGaugeFragment.java    From hawkular-android-client with Apache License 2.0 4 votes vote down vote up
private void detectLeaks() {
    RefWatcher refWatcher = HawkularApplication.getRefWatcher(getActivity());
    refWatcher.watch(this);
}
 
Example 16
Source File: BaseFragment.java    From Yuan-WanAndroid with Apache License 2.0 4 votes vote down vote up
@Override
public void onDestroy() {
    super.onDestroy();
    RefWatcher refWatcher = App.getRefWatcher(mActivity);
    refWatcher.watch(this);
}
 
Example 17
Source File: MetricCounterFragment.java    From hawkular-android-client with Apache License 2.0 4 votes vote down vote up
private void detectLeaks() {
    RefWatcher refWatcher = HawkularApplication.getRefWatcher(getActivity());
    refWatcher.watch(this);
}
 
Example 18
Source File: LeakWatchFragment.java    From AcDisplay with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void onDestroy() {
    super.onDestroy();
    RefWatcher refWatcher = AppHeap.getRefWatcher();
    refWatcher.watch(this);
}
 
Example 19
Source File: BaseFragment.java    From OPFPush with Apache License 2.0 4 votes vote down vote up
@Override
public void onDestroy() {
    super.onDestroy();
    final RefWatcher refWatcher = getPushChatApplication().getRefWatcher();
    refWatcher.watch(this);
}
 
Example 20
Source File: AbstractSimpleFragment.java    From Awesome-WanAndroid with Apache License 2.0 4 votes vote down vote up
@Override
public void onDestroy() {
    super.onDestroy();
    RefWatcher refWatcher = WanAndroidApp.getRefWatcher(_mActivity);
    refWatcher.watch(this);
}