Q:

How do I instantly disable my done button when I switch to airplane mode? 

I have a done button in my app which I would like to disable when I switch to airplane mode.  I have working code for the same in my app.  However, it doesn't disable as soon as I switch my app to airplane mode.  It disables only when I switch to some other view and then return to this view.  Is there a way I can instantly disable it, the moment my app detects offline mode?  Here's my code so far:
  private static boolean isAirplaneModeOn(Context context) {

            return Settings. System.getInt(context.getContentResolver(),
                    Settings. System. AIRPLANE_MODE_ON, 0) ! = 0;

        }

In my oncreateview, I have:
if(isAirplaneModeOn(Application.getAppContext())){
            Toast toast = Toast.makeText(this.getActivity(),getResources().getString(R.string.offline), Toast. LENGTH_SHORT);
            toast.setGravity(Gravity. CENTER, 0, 0);
            toast.show();
            mDoneBtn.setActivated(false);
            mDoneBtn.setTextColor(Color. DKGRAY);
            mDoneBtn.setOnClickListener(null);

        }else {
            mDoneBtn.setOnClickListener(this);
        }

Is there any other way of doing this which is better?  or can this be improved to achieve my goal?  Any ideas? 
Thanks! 

A:

Why not trying disabling it: 
IntentFilter intentFilter = new IntentFilter("android.intent.action. AIRPLANE_MODE");

BroadcastReceiver receiver = new BroadcastReceiver() {
  @Override
  public void onReceive(Context context, Intent intent) {
       if (! isAirplaneModeOn(this)) { 
          mDoneBtn.setEnabled(false);
       } else { 
          mDoneBtn.setEnabled(true); 
       } 
  }
 };

context.registerReceiver(receiver, intentFilter);

@Override
public void onDestroy() {
    super.onDestroy();
    unregisterRecievers();
}

private void unregisterRecievers() {
    try {
        unregisterReceiver(receiver);
    } catch (Exception e) {
        e.printStackTrace();
    }

}

