我正在使用 SMS 监听器,代码如下:
public class SMSReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
EventEntry entry = ((MyApplication)context.getApplicationContext()).getCurrent();
System.out.println("Received message: " + smsMessage[0].getMessageBody() + " - SILENCE IS " + ((entry != null) ? "ON" : "OFF"));
}
}
并在修改 AndroidManifest 之后
<application
android:name="MyApplication" ...
在我的代码的另一部分(在 AlarmManager 的 BroadcastReceiver 中),我有
public void onReceive(Context context, Intent intent) {
((MyApplication).context.getApplicationContext()).setCurrent("TESTING");
}
但是,当我运行应用程序并发送示例文本时,我会收到以下调试消息:
09-15 15:07:30.974: I/System.out(21625): DEBUG!!!!!! Setting current event to TESTING
09-15 15:07:54.399: I/System.out(21605): DEBUG!!!!!! Getting current event: null
任何想法为什么我的应用程序上下文不同步?
谢谢!