Android靜態註冊內部類廣播BroadcastReceiver

用靜態註冊內部類廣播出現異常

09-14 11:31:25.576: E/AndroidRuntime(3391): 

FATAL EXCEPTION: main
09-14 11:31:25.576: E/AndroidRuntime

(3391): java.lang.RuntimeException: Unable to instantiate 

receiver com.jtd.service.Service$InsideService: 

java.lang.InstantiationException: can't instantiate class 

com.jtd.service.Service$InsideService; no empty 

constructor


將內部類改成static class

public class Service {
 

   public static class InsideService extends BroadcastReceiver {

	@Override
	public void onReceive(Context context, Intent intent) {
	    Log.e("Service", "..onReceive..0914");

	} 
    }
}


在AndroidManifest.xml中定義

<receiver android:name="com.jtd.service.Service$InsideService" >
        <intent-filter>
                <action android:name="com.jtd.service.Service.InsideService" />
        </intent-filter>
</receiver>


內部類加入$符號

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章