Running a service with Calendar time checking
<p>I'm writing an application about notification. I want to notify user at 6PM everyday (no matter minute or sec) even if they closed app. I used a Service to let my program run and cannot be close (Service -> onStartCommand -> STICKY).
I know in function onStartCommand can help me check the time. But it only can check 1 time, not everytime. I'm finding the way to writing some code lines to my service class to let it check everytime.
This is my Service class:</p>

<pre><code>package com.truonghau.smstoxls.service;

import android.app.NotificationManager;
import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.os.IBinder;
import android.util.Log;

import com.truonghau.xmeasure.commons.Constants;
import com.truonghau.xmeasure.commons.SmSUtils;

import java.util.Calendar;

/**
 * Created by HieuK on 12/05/16.
 */
public class Services extends Service {
    private static final String LOG_TAG = "ForegroundService";
    public static boolean IS_SERVICE_RUNNING = false;

    @Override
    public IBinder onBind(Intent intent) {
        return null;
    }

    @Override
    public void onCreate() {
        super.onCreate();
    }

    @Override
    public int onStartCommand(Intent intent, int flags, int startId) {

        NotificationManager mNM = (NotificationManager)getApplicationContext().getSystemService(Context.NOTIFICATION_SERVICE);
        if (intent.getAction().equals("BD"))
        {
            Calendar cal = Calendar.getInstance();
            int h18 = cal.get(Calendar.HOUR_OF_DAY);
            if (h18 == 18)
            {
                //solve
            }
            SmSUtils.showNotification(getApplicationContext(),mNM,"Started",false);
        }
        if (intent.getAction().equals("KT"))
        {
            SmSUtils.showNotification(getApplicationContext(),mNM,"Ended",false);
            stopForeground(true);
            stopSelf();
        }

        return START_STICKY;
    }
}
</code></pre>