package com.cky.learnandroiddetails.AndroidApiGuide.MessengerTest;

import android.app.Service;
import android.content.Intent;
import android.os.Handler;
import android.os.IBinder;
import android.os.Message;
import android.os.Messenger;
import android.support.annotation.Nullable;
import android.widget.Toast;

/**
 * Created by cuikangyuan on 2017/12/8.
 */

public class MessengerService extends Service {


    public static final int MSG_SAY_HELLO = 1;

    final Messenger mMessenger = new Messenger(new IncomingHandler());

    class IncomingHandler extends Handler {

        @Override
        public void handleMessage(Message msg) {

            switch (msg.what) {
                case MSG_SAY_HELLO:
                    Toast.makeText(getApplicationContext(), "hello", Toast.LENGTH_SHORT).show();
                    break;
                default:
                    super.handleMessage(msg);
            }
        }
    }

    @Nullable
    @Override
    public IBinder onBind(Intent intent) {
        Toast.makeText(getApplicationContext(), "binding...", Toast.LENGTH_SHORT).show();
        return mMessenger.getBinder();
    }
}

@@ -1135,11 +1135,213 @@
 );%0A    %7D
+%0A%0A    @Override%0A    public boolean onUnbind(Intent intent) %7B%0A        return super.onUnbind(intent);%0A    %7D%0A%0A    @Override%0A    public void onRebind(Intent intent) %7B%0A        super.onRebind(intent);%0A    %7D%0A%0A
 %0A%7D%0A

modify messenger service demo