小编del*_*san的帖子

LeakCanary通过匿名实现locationlistener报告泄露的活动实例

在onDestroy中

locationManager.removeUpdates(locationListener);
locationListener = null;
Run Code Online (Sandbox Code Playgroud)

匿名实现

locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);
        if (locationManager != null) {
            locationListener = new LocationListener() {
                @Override
                public void onLocationChanged(Location location) {
                    if (chatId != null) {
                        double radius = 6378.137;
                        double oldLat = mLastLocation.getLatitude();
                        double oldLng = mLastLocation.getLongitude();
                        double newLat = location.getLatitude();
                        double newLng = location.getLongitude();
                        double dLat = Math.toRadians(newLat - oldLat);
                        double dLng = Math.toRadians(newLng - oldLng);
                        double a = Math.sin(dLat / 2) * Math.sin(dLat / 2)
                                + Math.cos(Math.toRadians(oldLat))
                                * Math.cos(Math.toRadians(newLat)) * Math.sin(dLng / …
Run Code Online (Sandbox Code Playgroud)

android memory-leaks anonymous-inner-class leakcanary

9
推荐指数
1
解决办法
773
查看次数