Reputation: 724
I have a class of contentobserver
, I want to send broasdcast message from contentobserver
. But when its call app crash and I see the logcate context is null
please tell me how can I send message from contentresolver
.
Here is my code:
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);
}
}
Upvotes: 0
Views: 500
Reputation: 129
Can you try to pass the application context to the 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);
}
}
Upvotes: 1