用靜態註冊內部類廣播出現異常
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>
內部類加入$符號