我有一类contentobserver
,我想从contentobserver
发送broasdcast消息。但是当它的调用应用程序崩溃并且我看到logcate上下文为null
时,请告诉我如何从contentresolver
发送消息。
这是我的代码:
public class SettingsContentObserver extends ContentObserver {
Context context;
public SettingsContentObserver(Handler handler) {
super(handler);
}
@Override
public boolean deliverSelfNotifications() {
return super.deliverSelfNotifications();
}
@Override
public void onChange(boolean selfChange) {
super.onChange(selfChange);
//Profile1Activity.profile1(context);
Intent i = new Intent("settingschanged");
context.sendBroadcast(i);
}
}
答案 0 :(得分:1)
您可以尝试将应用程序上下文传递给ContentObserver吗?
public class SettingsContentObserver extends ContentObserver {
Context mContext;
public SettingsContentObserver(Handler handler, Context context) {
super(handler);
this.mContext = context;
}
@Override
public boolean deliverSelfNotifications() {
return super.deliverSelfNotifications();
}
@Override
public void onChange(boolean selfChange) {
super.onChange(selfChange);
//Profile1Activity.profile1(context);
Intent i = new Intent("settingschanged");
mContext.sendBroadcast(i);
}
}