how to use leakcanary, how to add leakcanary as a jar to build a apk with .mk file

后端 未结 5 1458
独厮守ぢ
独厮守ぢ 2021-01-18 02:07

LeakCanary is a memory leak detection library for Android and Java. LeakCanary

My project is based on android make file system, which relies on some android internal

5条回答
  •  再見小時候
    2021-01-18 02:20

    This is needed to be part of your application in order for leakcanary to work.

    public class ExampleApplication extends Application {
    
     @Override public void onCreate() {
      super.onCreate();
      LeakCanary.install(this);
     }
    }
    

    but this is confusing because most of us do not write such kind of class that extends the Application class directly, a work around rather a simple statement will fix this problem,

    public class YourClass extends Activity{//AppCompatActivity, A  ctionBarActivity or anything
    
    @Override public void onCreate() {
      super.onCreate();
       LeakCanary.install(getApplication());
     }
    }
    

    hope this helps!!!

    Its better to call this method in

       onPostCreate()
    

提交回复
热议问题