Android静态注册内部类广播BroadcastReceiver

来源:互联网 发布:40不惑50知天命60 编辑:程序博客网 时间:2024/05/16 12:00

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


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

[plain] view plaincopy
  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 plaincopy
  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 plaincopy
  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>  


内部类加入$符号


0 0
原创粉丝点击