BlockCanary interface detection Caton

Add dependence:

  implementation  'com.github.markzhai:blockcanary-android:1.5.0'

After running the tool will be installed to detect, detect major UI thread running Caton phenomenon

public class MainActivity extends AppCompatActivity {

    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        SystemClock.sleep(1000);
    }

    }

Let the main interface Caton 1 second

public class MyApplication extends Application {
    @Override
    public void onCreate() {
        super.onCreate();
        BlockCanary.install(this, new AppContext()).start();

    }

    public  class the AppContext the extends BlockCanaryContext {
         // the default threshold is Caton 1000ms 
        public  int provideBlockThreshold () {
             return 1000 ;
        }
        // log output 
        public String providePath () {
             return "/ blockcanary /" ;
        }
        // A file upload 
        public  void the Upload (File zippedFile) {
             the throw  new new UnsupportedOperationException ();

        }
        // can provide custom operations Caton 
        @Override
         public  void onBlock (the Context context, BlockInfo BlockInfo) {
            System.out.println ( "blocking operation" );
        }
    }
}

Caton detected more than one second output log

<application
        android:name=".MyApplication"
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"

Statement name attribute

Guess you like

Origin www.cnblogs.com/Ocean123123/p/11025102.html