title: Android 5.1 -How do i update the UI change when i change configuration from notification tray?
body: <p>I have a simple app that change that toggle the silent mode to normal or vice versa. But the problem is that i can just drag the notification tray can change the mode from silent to normal and i want the Volume icon inside the also change to normal icon.</p>
  
  <p>In which state the application goes in when i pull down the Tray Notification ?</p>
  
  <p><a href="https://i.stack.imgur.com/HmkoF.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/HmkoF.png" alt="enter image description here"></a></p>
  
  <p>Now When i tap the mute to normal mode from tray, which method should i put my update method to reflect the changes. </p>
  
  <p>The uiupdate </p>
  
  <p>I tried callinf updateUI method onResume but doesn;t seems to work as the application doesn't seem to be pause.</p>
  
  <p>MainActivity.java</p>
  
  <pre><code>package com.example.manis.silentmodetoggle;
  
  import android.app.Activity;
  import android.media.AudioManager;
  import android.os.Bundle;
  import android.util.Log;
  import android.view.View;
  import android.widget.FrameLayout;
  import android.widget.ImageView;
  
  public class MainActivity extends Activity {
  
      private AudioManager audioManager;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
  
          Log.v("myTest","called onCreate");
          setContentView(R.layout.activity_main);
  
          //reference to the audio manager
          audioManager = (AudioManager) getSystemService(AUDIO_SERVICE);
          FrameLayout contentView = (FrameLayout) findViewById(R.id.content);
  
          updateUi();
  
          contentView.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                  RingerHelper.performToggle(audioManager);
                  updateUi();
              }
          });
      }
  
      private void updateUi(){
          ImageView imageView = (ImageView) findViewById(R.id.imageView);
  
          //Set The PhoneImage
          int phoneImage =RingerHelper.isPhoneSilent(audioManager) ? R.drawable.noaudio_96: R.drawable.highvolume_96 ;
  
          imageView.setImageResource(phoneImage);
      }
  
      @Override
      protected void onStart() {
          super.onStart();
          Log.v("myTest","Called onStart");
  
      }
  
      @Override
      protected void onResume() {
          super.onResume();
          Log.v("myTest","Called onResume");
          updateUi();
  
      }
  
      @Override
      protected void onPostResume() {
          super.onPostResume();
          Log.v("myTest","Called onPostResume");
      }
  
  
  
      @Override
      protected void onPause() {
          super.onPause();
          Log.v("myTest","Called onPause");
      } 
   }
  
  package com.example.manis.silentmodetoggle;
  
  import android.media.AudioManager;
  
  
  public class RingerHelper {
  
      private RingerHelper(){};
  
      public static void performToggle(AudioManager audioManager)
      {
         //if the phone is currently silent then set ot normal
          //if normal then set to silent
          audioManager.setRingerMode(
                  isPhoneSilent(audioManager)? AudioManager.RINGER_MODE_NORMAL : AudioManager.RINGER_MODE_SILENT
          );
      }
  
      public  static  boolean isPhoneSilent(AudioManager audioManager){
          return audioManager.getRingerMode() == AudioManager.RINGER_MODE_SILENT;
  
      }
  }
  </code></pre>
  
  <p>ps:This is sample app from Android App development from dummies book.</p>