title: Android service mysql - check for database change
body: <p>I'm developing android application. I need to run service to check for database update every few seconds and notify the user if changed.</p>
  
  <p>Is the use of service a good way to solve this problem?</p>
  
  <p>Here is part of my code. So far I didn't make it work.</p>
  
  <p>Any help?</p>
  
  <pre><code>public class NotificationService extends Service  {
  
  private Timer mTimer;
  public static final String MyPREFERENCES = "MyPrefs" ;
  SharedPreferences sharedpreferences;
  public String formattedDate, restoredText;
  
  @Nullable
  @Override
  public IBinder onBind(Intent intent) {
      return null;
  }
  
  @Override
  public void onCreate() {
      super.onCreate();
      mTimer = new Timer();
      mTimer.schedule(timerTask,2000,15*1000);
      Log.d("TEST","TEST");
  
  }
  
  @Override
  public int onStartCommand(Intent intent, int flags, int startId) {
      try{
  
      }catch (Exception e){
          e.printStackTrace();
      }
      return super.onStartCommand(intent, flags, startId);
  }
  
  TimerTask timerTask = new TimerTask() {
      @Override
      public void run() {
          Log.e("Log", "Running");
          SharedPreferences prefs = getSharedPreferences(MyPREFERENCES, MODE_PRIVATE);
          restoredText = prefs.getString("username", null);
          if (restoredText != null) {
  
              Calendar c = Calendar.getInstance();
              SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
              formattedDate = df.format(c.getTime());
              //notifiy(); //ovdje cemo ga privremeno iskljuciti
  
              /*
  
                  here I need implement code for checking data from remotly mysql database
              */
  
  
          }else {
              notifiy();
          }
      }
  };
  </code></pre>