title: Service for posting data to server in Android even if app is closed (offline to online)
body: <p>I am working on an android app, which will take input from the user (sort of form, simulated chat) and store it in the local database.
  I have created BroadcastReceiver to get the network changed status, if connected I start posting the data to the server.</p>
  
  <pre><code>public class NetworkChangeReceiverService extends BroadcastReceiver {
  
      @Override
      public void onReceive(Context context, Intent intent) {
  
          if (Connectivity.isConnected(context)) {
              Logger.d("Connected to internet");
              // Post data to the server.
          } else {
              Logger.d("Not connected to internet");
          }
      }
  }
  </code></pre>
  
  <p>Is this the right approach. Would be a great help if you specify the details of the posting the data to the server, like should I use AsyncTask or go with just the plain Retrofit thing, I want to keep the memory consumption as low as possible while the receiver and posting works in the background. Alos, if, possible would like to know the working of WhatsApp for the same.</p>