title: Building a notification using Timer()
body: <p>I want to create a notification in my application that warns me everytime there's an UPDATE or a new entry in my SQL Server database.
  i used Timer() and i compared the new data with the old data, but the problem is that it only notify me when i log in and it sends the notification continuously.
  i want to be warned even if i'm not in the app.</p>
  
  <pre><code>Timer timer = new Timer();
  timer.schedule(new TimerTask() {
      @Override
      public void run() {
  
          runOnUiThread(new Runnable() {
              @Override
              public void run() {
                  String user = "", pass = "";
                  Bundle b = ActivityTwo.this.getIntent().getExtras();
                  if (b != null) {
                      user = b.getString("user");
                      pass = b.getString("pass");
                  }
                  String q12 = "Select TOP(6) readingdate,hp07,hp10 from Workers,TLD where card=cardID AND username='" + user + "' AND password='" + pass + "' order by readingdate desc ";
                  try {
                      connect = ConnectionHelper(username, password, db, ipaddress);
                      if (connect == null) {
                          new AlertDialog.Builder(ActivityTwo.this).setTitle("Error Message")
                                  .setMessage("Error in connection!!")
                                  .setNeutralButton("OK", new DialogInterface.OnClickListener() {
  
                                      @Override
                                      public void onClick(DialogInterface dialog, int which) {
                                          // TODO Auto-generated method stub
                                      }
                                  }).show();
                      } else {
                          s12 = connect.prepareStatement(q12);
                          r12 = s12.executeQuery();
                          int[] ka = new int[6];
                          int c = 0;
                          while (r12.next()) {
                              String h07 = r12.getString("hp07");
                              String h10 = r12.getString("hp10");
                              int l07 = Integer.valueOf(h07);
                              ka[c] = l07;
                              c++;
                              //Toast.makeText(ActivityTwo.this, hp071 + " " + h07 + " " + hp101 + " " + h10, Toast.LENGTH_SHORT).show();
                              for (int i = 0; i &lt; 6; i++) {
                                  if (ka[i]!=hp071[i]) {
                                      final Intent emptyIntent = new Intent(ActivityTwo.this, MainActivity.class);
                                      PendingIntent pendingIntent = PendingIntent.getActivity(ActivityTwo.this, 0, emptyIntent, PendingIntent.FLAG_UPDATE_CURRENT);
  
                                      android.support.v7.app.NotificationCompat.Builder mBuilder =
                                              (android.support.v7.app.NotificationCompat.Builder) new android.support.v7.app.NotificationCompat.Builder(ActivityTwo.this)
                                                      .setSmallIcon(R.mipmap.ic_launcher)
                                                      .setContentTitle("My notification")
                                                      .setContentText("NEW UPDATE")
                                                      .setContentIntent(pendingIntent);
                                      mBuilder.setTicker("this is the notif");
                                      mBuilder.setAutoCancel(true);
                                      mBuilder.setWhen(System.currentTimeMillis());
                                      mBuilder.setOngoing(true);
                                      Notification not = mBuilder.build();
                                      not.defaults |= Notification.DEFAULT_VIBRATE;
                                      not.defaults |= Notification.DEFAULT_SOUND;
  
                                      NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
                                      notificationManager.notify(1, not);
                                      hp071[i]=ka[i];
                                  }
                              }
                          }
                      }
                  } catch (SQLException e) {
                      e.printStackTrace();
                  }
              }
          });
      }
  }, 0);
  </code></pre>
  
  <p>so where is my mistake?? the app is not that complicated to use the google cloud messaging, just a simple warning.</p>