title: Background Processing in android using Intent service
body: <p>I am trying to do Background Processing in android using Intent-service, In my project user can able to store a number of records in SQLite(when a user at offline mode), Whenever user connected WiFi or mobile data user trying to sync offline data and simultaneously he is entering new data in SQLite.</p>
  
  <p>When user enter new records while sync the data device performance is very slow and UI also freezing, Anything wrong in my way of process can someone help me, please  </p>
  
  <h2>code:-</h2>
  
  <pre><code>public class NetworkIntentServiceForOfflineDetails extends IntentService {
  
      // IntentService can perform, e.g. ACTION_FETCH_NEW_ITEMS
      private static final String ACTION = ConnectivityManager.CONNECTIVITY_ACTION;
      //private NetworkChangeReceiver networkChangeReceiver;
      public NetworkIntentServiceForOfflineDetails() {
          super("NetworkIntentService");
      }
  
      @Override
      protected void onHandleIntent(Intent intent) {
          if (intent != null) {
  
              DatabaseAccess databaseAccess = new DatabaseAccess(this);
              databaseAccess.open();
              List&lt;OfflineDataObj&gt; offlineInfo = databaseAccess.getDetailsInfo();
              databaseAccess.close();
              UserPreferences.setPreferenceBoolean(Constants.IS_ALARM_ON, false);
              if (offlineInfo.size() == 0) {
             Toast.LENGTH_SHORT).show();
              } else if (NetWorkConnection.isConnected()) {
  
                  try {
                      for(int i = 0 ; i &lt; offlineInfo.size(); i++) {
  
                              OfflineDataObj offlineDataObj = offlineInfo.get(i);
                              String userId = UserPreferences.getPreferenceString(Constants.USER_ID,
                                      null);
                              String url = ServerUrls.SUBMIT_PROJECT_DETAILS_TO_SERVER + userId + "/" + "project_submissions";
  
  VolleyHelperPostForOffline().callVolleyHelperPost(url, offlineDataObj.getJson(),
                                    Constants.NOTIFICATION_SUBMIT_PROJECT_DETAILS_TO_SERVER, this, null,
                                      offlineDataObj);
  
                      }
                  } catch (Throwable throwable) {
                      throwable.printStackTrace();
                  }
              } else {
                  setAlarm();
              }
          }
      }
  
      @Override
      public void onDestroy() {
          super.onDestroy();
      }
  
      private void setAlarm() {
          UserPreferences.setPreferenceBoolean(Constants.IS_ALARM_ON, true);
          PendingIntent pendingIntent;
          Intent myIntent = new Intent(NetworkIntentServiceForOfflineDetails.this, NetworkIntentServiceForOfflineDetails.class);
          pendingIntent = PendingIntent.getService(NetworkIntentServiceForOfflineDetails.this, 0, myIntent, 0);
          AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
          alarmManager.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + Constants.ALARM_TIME_FOR_OFFLINEDATA, pendingIntent);
      }
  }
  </code></pre>