我在主活动中创建了一个广播接收器和一个后台服务,该服务正在发送广播意图。每次尝试运行应用程序时,应用程序都会崩溃,并且日志显示以下错误消息:
10-04 13:30:43.218: ERROR / AndroidRuntime(695): java.lang.RuntimeException:Error 接收广播意图{ action = com.client.gaitlink.CommunicationService.action.LOGIN_STATUS_UPDATE (有额外内容)}在 com.client.gaitlink.GaitLink $LoginStatusReceiver @ 431690e8
广播消息是从CommunicationService类的以下方法中发送的:
private void announceLoginStatus(){
Intent intent = new Intent(LOGIN_STATUS_UPDATE);
intent.putExtra(SERVER_MESSAGE, mServerResponseMessage);
intent.putExtra(SESSION_STRING, mSessionString);
sendBroadcast(intent);
}
在哪里
String LOGIN_STATUS_UPDATE = "com.client.gaitlink.CommunicationService.action.LOGIN_STATUS_UPDATE"
在主活动中定义了以下广播接收器:public class LoginStatusReceiver extends BroadcastReceiver {
public void onReceive(Context context, Intent intent) {
String serverMessage = intent.getStringExtra(CommunicationService.SERVER_MESSAGE);
String sessionString = intent.getStringExtra(CommunicationService.SESSION_STRING);
userInfo.setSessionString(sessionString);
saveSettings();
}
}
在onResume方法中注册:
IntentFilter loginStatusFilter;
loginStatusFilter = new IntentFilter(CommunicationService.LOGIN_STATUS_UPDATE);
loginStatusReceiver = new LoginStatusReceiver();
registerReceiver(loginStatusReceiver, loginStatusFilter);
清单文件包括以下内容:
<activity android:name=".GaitLink"
android:label="@string/app_name">
<intent-filter>
...
<action android:name="com.client.gaitlink.CommunicationService.action.LOGIN_STATUS_UPDATE" />
</intent-filter>
</activity>
如果有人能够解释为什么日志记录了上面的消息并且应用程序崩溃,我将不胜感激。
谢谢!