1、New→Other→BroadcastReceiver
package com.example.lhb.startservice;import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.widget.Toast;public class MyReceiver extends BroadcastReceiver {public MyReceiver() {}public static final String ACTION="com.example.lhb.startservice.intent.action.MyReceiver";//约定俗成,包名+intent.action+MyReceiver@Overridepublic void onReceive(Context context, Intent intent) {System.out.println("接收到了消息:"+intent.getStringExtra("data"));throw new UnsupportedOperationException("Not yet implemented");}
}
2、主程序
package com.example.lhb.startservice;import android.app.Activity;
import android.content.Intent;
import android