Is this Runnable safe from memory leak?

前端 未结 4 848
野的像风
野的像风 2021-01-18 05:58

I am a total beginner in Java and have created a simple Java Android snippet where in a Runnable after 1,5 seconds I change the TextView from Hello World<

4条回答
  •  情歌与酒
    2021-01-18 06:26

    I have a doubt if there's absolutely no memory leak whenever device orientation occurs.

    It could be. For 1.5seconds. After the queue is emptied the handler can be garbage collected, and also the old Activity. To be safe override onPause, and call handler.removeCallbacks(null); to clear the Handler's queue

提交回复
热议问题