Android service called data from list multiple times
<p><em><strong>1.hello, I have created service for Schedule message but the problem is i have set the loop in my service method but it send the message all the message that is set on list.</em></strong></p>

<p><em><strong>2.I want to set the loop like, send message on list will be send at least ones time.</em></strong></p>

<p><em><strong>3.And the message has been sent is not send again.</em></strong></p>

<p>//<strong><em>Here is my code.</em></strong>
//MyService class</p>

<pre><code>import java.util.ArrayList;
import java.util.List;
import android.app.Activity;
import android.app.PendingIntent;
import android.app.Service;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.IBinder;
import android.telephony.gsm.SmsManager;
import android.util.Log;
import android.widget.Toast;
public class SchedulerMsgService extends Service {
    private static final String TAG = "MyService";
    private DatabaseHelper mDbHelper;
    private ArrayList&lt;schedulerDetails&gt; myschedule = new ArrayList&lt;schedulerDetails&gt;();
    private String phoneNo, message, sDate, curTime;

    @Override
    public IBinder onBind(Intent intent) {
        // TODO Auto-generated method stub
        return null;
    }
    @Override
    public void onCreate() {
        // TODO Auto-generated method stub
        Toast.makeText(this, "My Service Created", Toast.LENGTH_LONG).show();
        Log.d(TAG, "onCreate");
    }
    @Override
    public void onDestroy() {
        Toast.makeText(this, "My Service Stopped", Toast.LENGTH_LONG).show();
        Log.d(TAG, "onDestroy");
    }
    @Override
    public void onStart(Intent intent, int startId) {
        Log.d(TAG, "oNsTART IS rEADY ");
        mDbHelper = new DatabaseHelper(this);
        final List&lt;schedulerDetails&gt; ScheduleList = mDbHelper.selectAllNumbers();
        for (int j = 0; j &lt; ScheduleList.size(); j++) {
            myschedule.add(ScheduleList.get(j));
            phoneNo = myschedule.get(j).num;
            message = myschedule.get(j).textMessage;
            sDate = myschedule.get(j).date;
            curTime = myschedule.get(j).time;

            sendSMS(phoneNo, message, sDate, curTime);
        }


        Toast.makeText(this, "condition Matched", Toast.LENGTH_LONG).show();

        // Toast.makeText(this, "condition Not Matched",
        // Toast.LENGTH_LONG).show();
    }
    public void sendSMS(String phoneNo, String message, String sDate,
            String curTime) {
        String SENT = "SMS_SENT";
        String DELIVERED = "SMS_DELIVERED";
        PendingIntent sentPI = PendingIntent.getBroadcast(this, 0, new Intent(
                SENT), 0);
        PendingIntent deliveredPI = PendingIntent.getBroadcast(this, 0,
                new Intent(DELIVERED), 0);
        registerReceiver(new BroadcastReceiver() {
            @Override
            public void onReceive(Context context, Intent intent) {
                switch (getResultCode()) {
                case Activity.RESULT_OK:
                    Toast.makeText(getBaseContext(), "SMS Sent",
                            Toast.LENGTH_SHORT).show();
                    break;
                case SmsManager.RESULT_ERROR_GENERIC_FAILURE:
                    Toast.makeText(getBaseContext(), "Generic Failure",
                            Toast.LENGTH_SHORT).show();
                    break;
                case SmsManager.RESULT_ERROR_NO_SERVICE:
                    Toast.makeText(getBaseContext(), "Null Service",
                            Toast.LENGTH_SHORT).show();
                    break;
                case SmsManager.RESULT_ERROR_NULL_PDU:
                    Toast.makeText(getBaseContext(), "Null PDU",
                            Toast.LENGTH_SHORT).show();
                    break;
                case SmsManager.RESULT_ERROR_RADIO_OFF:
                    Toast.makeText(getBaseContext(), "Radio Off",
                            Toast.LENGTH_SHORT).show();
                    break;
                }
            }
        }, new IntentFilter(SENT));
        registerReceiver(new BroadcastReceiver() {
            @Override
            public void onReceive(Context context, Intent intent) {
                switch (getResultCode()) {
                case Activity.RESULT_OK:
                    Toast.makeText(getBaseContext(), "SMS Delivered",
                            Toast.LENGTH_SHORT).show();
                    break;
                case Activity.RESULT_CANCELED:
                    Toast.makeText(getBaseContext(), "SMS not Delivered",
                            Toast.LENGTH_SHORT).show();
                    break;
                }
            }
        }, new IntentFilter(DELIVERED));
        SmsManager sms = SmsManager.getDefault();
        sms.sendTextMessage(phoneNo, null, message, sentPI, deliveredPI);
    }
}
</code></pre>
