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

前端 未结 7 1822
深忆病人
深忆病人 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:21

    This way worked well for me, keeps code clean by keeping where you handle the message in its own inner class.

    The handler you wish to use

    Handler mIncomingHandler = new Handler(new IncomingHandlerCallback());
    

    The inner class

    class IncomingHandlerCallback implements Handler.Callback{
    
            @Override
            public boolean handleMessage(Message message) {
    
                // Handle message code
    
                return true;
            }
    }
    

提交回复
热议问题