This Handler class should be static or leaks might occur: IncomingHandler

前端 未结 7 1839
深忆病人
深忆病人 2020-11-22 07:14

I\'m developing an Android 2.3.3 application with a service. I have this inside that service to communicate with Main activity:

public class UDPListenerServi         


        
相关标签:
7条回答
  • 2020-11-22 07:31

    I'm confused. The example I found avoids the static property entirely and uses the UI thread:

        public class example extends Activity {
            final int HANDLE_FIX_SCREEN = 1000;
            public Handler DBthreadHandler = new Handler(Looper.getMainLooper()){
                @Override
                public void handleMessage(Message msg) {
                    int imsg;
                    imsg = msg.what;
                    if (imsg == HANDLE_FIX_SCREEN) {
                        doSomething();
                    }
                }
            };
        }
    

    The thing I like about this solution is there is no problem trying to mix class and method variables.

    0 讨论(0)
提交回复
热议问题