Handlers and memory leaks in Android

前端 未结 6 2134
攒了一身酷
攒了一身酷 2020-11-29 18:14

Please have a look at the code below:

public class MyGridFragment extends Fragment{

     Handler myhandler = new Handler() {
    @Override
    public void h         


        
6条回答
  •  情歌与酒
    2020-11-29 18:34

    Per the ADT 20 Changes, it looks like you should make it static.

    New Lint Checks:

    Check to make sure that Fragment classes are instantiatable. If you accidentally make a fragment innerclass non-static, or forget to have a default constructor, you can hit runtime errors when the system attempts to reinstantiate your fragment after a configuration change.

    Look for handler leaks: This check makes sure that a handler inner class does not hold an implicit reference to its outer class.

提交回复
热议问题