title: Updating Notification Continuously
body: <p>Hello There I am a newbie for Android Development, working to learn it to my own!
  I just want to update my notification in a Java Thread in my application (I am just learning and curious about how can I do it).</p>
  
  <hr>
  
  <p>I have an activity, a simple thread to increment an Integer value. Then, I just want to show it in my Notification whenever the Integer value increments!
  My Code is as:</p>
  
  <pre><code>    public class MainActivity extends Activity{
          private final String LOG_KEY = this.getClass().getSimpleName();
          private int c = 0;
          private boolean flag = true;
          private NotificationCompat.Builder builder;
          private NotificationManager notificationManager;
  
          @Override
          protected void onCreate(Bundle savedInstanceState){
              super.onCreate(savedInstanceState);
              setContentView(R.layout.activity_main);
  
              builder = new NotificationCompat.Builder(MainActivity.this)
                 .setSmallIcon(R.mipmap.ic_launcher)
                 .setAutoCancel(false);
  
              builder.setOngoing(true);
  
              notificationManager = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
  
              Thread t = new Thread(new MyThread());
              t.start();
          }//OnCreate ends
  
          @Override
          protected void onStop() {
              super.onStop();
              flag = false;
          }//stop ends
  
          @Override
          protected void onDestroy() {
              super.onDestroy();
              flag = false;
          }//destroy ends
  
          private class MyThread implements Runnable {
              @Override
              public void run() {
                  while (flag) {
                      c+=1;
                      showNotification(Integer.toString(c) + " Counts");
                  }//while ends
              }//run ends
  
              private void showNotification(String msg) {
                  try {
                      //set the notification
                      builder.setContentText(msg);
                      notificationManager.notify(0, builder.build());
                  } catch (Exception exp) {
                      Log.e("xmn", exp.toString());
                  }//try catch ends
              }//showNotification ends
  
          }//private class ends
      }//MainActivity class ends here 
  </code></pre>
  
  <hr>
  
  <p><strong>As from my code, the notification appears and updates the value! But the problem is that it freezes the device and application at a sudden!</strong></p>
  
  <p><strong>I just want help for what I am doing wrong as I am a newbie and learning it to my own. Any help and idea will be highly appreciated!</strong></p>
  
  <hr>
  
  <p>Thanks</p>