title: How to show if charger is plugged in/out on an Activity?
body: <p>I am a newbie in android. I want to change a text of textview in an activity if a charger is plugged in or out. For that i have registered a receiver in manifest with intents <code>android.intent.action.ACTION_POWER_CONNECTED</code> <code>android.intent.action.ACTION_POWER_DISCONNECTED</code></p>
  
  <p>Following is the code for receiver:</p>
  
  <pre><code>public class PowerConnectionReceiver extends BroadcastReceiver {
  @Override
  public void onReceive(Context context, Intent intent) {
  
      if(intent.getAction() == Intent.ACTION_POWER_CONNECTED) {
          //Handle power connected
          Log.e("Charger State","power connected");
          Toast.makeText(context, "Charger PluggedIn", Toast.LENGTH_SHORT).show();
      } else if(intent.getAction() == Intent.ACTION_POWER_DISCONNECTED){
          //Handle power disconnected
          Log.e("Charger State","power disconnected");
          Toast.makeText(context, "Charger PluggedOut", Toast.LENGTH_SHORT).show();
      }
  
     }
  }
  </code></pre>
  
  <p>This is working perfectly but i want to show it on an activity when charger is plugged or unplugged. Please help me to acheive the task.</p>
  
  <p>Thanks~</p>