下面是我的 BroadcastReceiver
代码,我在其中遇到此错误:
java.lang.RuntimeException: Error receiving broadcast Intent { act=org.mosquitto.android.powerviewer.PING flg=0x4 (has extras)
我的代码:
public class PingSender extends BroadcastReceiver {
public void onReceive(Context context, Intent intent) {
context2 = context;
try {
System.err.println("MQTT IS NULLLLLLLLLLLLL");
mqttClient.ping();
} catch (MqttException e) {
Log.e("mqtt", "ping failed - MQTT exception", e);
try {
mqttClient.disconnect();
} catch (MqttPersistenceException e1) {
Log.e("mqtt", "disconnect failed - persistence exception", e1);
}
// reconnect
if (connectToBroker()) {
String deviceID = mPrefs.getString(PREF_DEVICE_ID, null);
;
deviceID = MQTT_CLIENT_ID + "/" + deviceID;
subscribeToTopic(deviceID);
}
}
// start the next keep alive period
scheduleNextPing();
}
}
最佳答案
请注意您是否正在覆盖任何 Android 生命周期事件并根据需要正确调用基类构造函数。
关于android - 接收广播 Intent 时出错?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10393935/