android app sends duplicate records to server through restful webservice

I have created an app where service runs after every 5 mins and get records from sqlite and send them to server and updates the status in the sqlite, the problem comes in the sql server database where a single row is inserted more than one time.

I don’t know what thing is causing this problem, on debugging my code i noticed that when sending one row to server debugger goes in a build in class of Timer, and again send the same record, I have a feeling that the timer is running again and again and updates the status after sending multiple records to server. please suggest what is the problem and what is the correct way to perform this task.

  • How can I join on a CSV varchar?
  • SQL to output line number in results of a query
  • 'Conversion failed' error is not captured while executing in C# or in stored procedure
  • Convert MySQL query to Microsoft SQL Server
  • Is there a way to retrieve a list of existing savepoints that have been defined in a transaction in MS SQL Server Management studio
  • What is the correct statement for a SQL WHERE Clause for finding a specific number format?
  • this is the code service class

    public class AlarmServices extends Service {
    private Timer myTimer;
    private SQLiteDB dbHelper;
    Cursor cursor;
    String where = "1=1";
    String Whatstatus;
    String FFCode, TerrCode, FFMgr;
    public void onCreate() {
        // TODO Auto-generated method stub
        myTimer = new Timer();
        myTimer.schedule(new TimerTask() {
            public void run() {
        }, 0, 5 * 60 * 1000); // 5 min 
        Log.e("syn process start", "yes");
    private void getDataFromDB() {
        dbHelper = new SQLiteDB(AlarmServices.this);;
        cursor = dbHelper.getInCompleteAttendance(where);
        int rows = cursor.getCount();
        if (rows > 0) {
            for (int i = 0; i < rows; i++) {
                int Id;
                String recvdate, ffcode, terr_code, drcode, drname, addr, createddate, ffmgr, shift, lat, lon,droidrefno,locAddress, sync_status, curr_date, date_only;
                Id = cursor.getInt(0);
                recvdate = cursor.getString(1);
                ffcode = cursor.getString(2);
                terr_code = cursor.getString(3);
                drcode = cursor.getString(4);
                drname = cursor.getString(5);
                addr = cursor.getString(6);
                createddate = cursor.getString(7);
                ffmgr = cursor.getString(8);
                shift = cursor.getString(9);
                lat = cursor.getString(10);
                lon = cursor.getString(11);
                droidrefno = cursor.getString(12);
                locAddress = cursor.getString(13);
                sync_status = cursor.getString(14);
                curr_date = cursor.getString(15);
                date_only = cursor.getString(16);
                // Sync Server
                ChkInsertDailyAttendanceOperation insertAttd = new ChkInsertDailyAttendanceOperation(AlarmServices.this,
                        recvdate, ffcode, terr_code, drcode, drname, locAddress,
                        createddate, ffmgr,shift,Double.parseDouble(lat),Double.parseDouble(lon),
        } else {
    public void scheduleAlarm() {
        Long time = new GregorianCalendar().getTimeInMillis() + 1000;
        Intent intentAlarm = new Intent(this, MyExtBroadcastReceiver.class);
        AlarmManager alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
        alarmManager.set(AlarmManager.RTC_WAKEUP, time, PendingIntent
                .getBroadcast(this, 1, intentAlarm,PendingIntent.FLAG_UPDATE_CURRENT));
    public static class MyExtBroadcastReceiver extends BroadcastReceiver {
        public void onReceive(Context context, Intent intent) {
            Toast.makeText(context, "Sync Process Running",
            Log.e("sync process running","yes");
    public IBinder onBind(Intent intent) {
        // TODO: Return the communication channel to the service.
        throw new UnsupportedOperationException("Not yet implemented");

    code of async task class

    public class ChkInsertDailyAttendanceOperation extends AsyncTask<String, Void, String> {
    String serverResponse;
    String Recv_Date, FF_code, Terr_code, Dr_code, Dr_name, Addr, Created_Date,Currdate,locAddr,
    FF_mgr, Shift, Droid_Ref_No,DateOnly;
    double Lat,Lng;
    String Response ="{\"Value\":true,\"Successful\":true}"; //"{\"Successful\":true}";
    Context cxt;
    UserSQLiteDB dbHelper;
    public ChkInsertDailyAttendanceOperation(Context context, String recv_Date,
            String ff_code, String terr_code, String dr_code, String dr_name,
            String locAddress,  String created_Date,String ff_mgr, String shift,double lat,double lng,String droid_Ref_No,String currdate,String dateonly  ) {
           // TODO Auto-generated constructor stub
        Recv_Date = recv_Date;
        FF_code = ff_code;
        Terr_code = terr_code;
        Dr_code = dr_code;
        Dr_name = dr_name;
        //Addr = addr;
        Created_Date = created_Date;
        FF_mgr = ff_mgr;
        Shift = shift;
        Lat = lat;
        Lng = lng;
        Droid_Ref_No =droid_Ref_No;
        locAddr = locAddress;
        Currdate =currdate;
        DateOnly =dateonly;
    protected String doInBackground(String... urls) {
        RestAPI restAPI = new RestAPI();
        JSONObject jsonObj = new JSONObject();
        try {
            jsonObj = restAPI.UserDailyAttendance(Recv_Date, FF_code,
                    Terr_code, Dr_code, Dr_name, locAddr, Created_Date, FF_mgr,
                    Shift,Lat, Lng,Droid_Ref_No);
            serverResponse = jsonObj.toString();
        } catch (Exception e) {
            // TODO Auto-generated catch block
            Log.e("catch block", serverResponse);
        Log.e("repsonse", serverResponse);
        return serverResponse;
    protected void onPostExecute(String result) {
        dbHelper = new SQLiteDB(cxt);;
            String SyncStatus;
            if (serverResponse.equals(Response)) {
                SyncStatus = "C";
            } else {
                SyncStatus = "I";
            dbHelper.updateDAILYATTENDANCE(Recv_Date, FF_code,
                    Terr_code, Dr_code, Dr_name, Addr, Created_Date, FF_mgr,
                    Shift,String.valueOf(Lat), String.valueOf(Lng),Droid_Ref_No,locAddr,SyncStatus,Currdate,DateOnly);
    protected void onPreExecute() {

    MS SQL Server is a Microsoft SQL Database product, include sql server standard, sql server management studio, sql server express and so on.