我有两个实现接收器。
第一次实现:
public class ApplicationStartListener extends BroadcastReceiver {
Context mContext;
@Override
public void onReceive(Context context, Intent intent) {
mContext = context;
Toast.makeText(mContext, "FUI", Toast.LENGTH_LONG).show();
Log.v("Server application FUI", intent.getAction());
}
此实现不起作用。
二次实施:
public class TestActiv extends Activity{
public void onCreate(Bundle bundle){
super.onCreate(bundle);
setContentView(R.layout.main);
final IntentFilter intentFilter = new IntentFilter();
intentFilter.addAction(Intent.ACTION_PACKAGE_CHANGED);
intentFilter.addAction(Intent.ACTION_PACKAGE_ADDED);
intentFilter.addAction(Intent.ACTION_PACKAGE_REPLACED);
intentFilter.addAction(Intent.ACTION_SCREEN_OFF);
intentFilter.addAction(Intent.ACTION_SCREEN_ON);
intentFilter.addAction(Intent.ACTION_CAMERA_BUTTON);
BroadcastReceiver broadcastReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
Log.v("Server applic", "FUI: " + intent.getAction());
}
};
registerReceiver(broadcastReceiver, intentFilter);
}
}
为什么不能先实现BroadcastReceiver?