android - This Handler class should be static or leaks may occur (null) -
this handler class should static or leaks may occur (null)
is 'class' message referring 'myactivity' here, since handler object , did declare static. should ignore or there should add, 'static' somewhere in 'myactivity' declaration (i tried , got errors). notice 'weakreference' suggested lint warning.
public class myactivity extends activity{ ... static handler handler; ... handler = new handler() { public void handlemessage(message msg) {
since handler object , did declare static
you declared data member static. however, using anonymous inner class, , therefore subclass of handler
not static
.
instead of:
handler = new handler() { public void handlemessage(message msg) { // cool stuff } };
use:
handler=new myveryownhandler();
where myveryownhandler
either regular java class or static
inner class:
private static class myveryownhandler extends handler { public void handlemessage(message msg) { // cool stuff } };
note error class needs static
; not object needs static
.
Comments
Post a Comment