Android静态注册内部类广播BroadcastReceiver

http://blog.csdn.net/zhangjm123/article/details/7978909


用静态注册内部类广播出现异常

[plain]  view plain copy
  1. 09-14 11:31:25.576: E/AndroidRuntime(3391):   
  2.   
  3. FATAL EXCEPTION: main  
  4. 09-14 11:31:25.576: E/AndroidRuntime  
  5.   
  6. (3391): java.lang.RuntimeException: Unable to instantiate   
  7.   
  8. receiver com.jtd.service.Service$InsideService:   
  9.   
  10. java.lang.InstantiationException: can't instantiate class   
  11.   
  12. com.jtd.service.Service$InsideService; no empty   
  13.   
  14. constructor  


将内部类改成static class

[java]  view plain copy
  1. public class Service {  
  2.    
  3.   
  4.    public static class InsideService extends BroadcastReceiver {  
  5.   
  6.     @Override  
  7.     public void onReceive(Context context, Intent intent) {  
  8.         Log.e("Service""..onReceive..0914");  
  9.   
  10.     }   
  11.     }  
  12. }  


在AndroidManifest.xml中定义

[html]  view plain copy
  1. <receiver android:name="com.jtd.service.Service$InsideService" >  
  2.         <intent-filter>  
  3.                 <action android:name="com.jtd.service.Service.InsideService" />  
  4.         </intent-filter>  
  5. </receiver>  


内部类加入$符号


评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值