title: start a service automatically if ram is cleared by user in android
body: <p>How to start a service automatically if Ram is cleared by user in android 
  I have created one broadcastReciever and starting the service 
  Sorry if I am not very cleared ..some time it is working means if  user clearing ram then still service is running but some times it is stopped and its not restarting. how to solve this problem </p>
  
  <p>2) I have used alarm manager but application  getting hanged frequently so I quit alarm manager 
  My code snippet are </p>
  
  <pre><code>public class RecieverToRestartService extends BroadcastReceiver {
  
      @Override
      public void onReceive(Context context, Intent intent) {
          try 
  {
  
              Intent  _restartServiceIntent = new Intent(context,InvendisGpsLoggerActivity.class);
              _restartServiceIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
              context.startService(_restartServiceIntent);
          } catch (Exception e) {
              e.printStackTrace();
          }
  
      }
  
  }
  </code></pre>
  
  <p>and in android manifest file </p>
  
  <pre><code>&lt;receiver   android:name="com.i.I.RecieverToRestartService"&gt;
              &lt;intent-filter&gt;
                  &lt;action android:name="android.intent.action.PACKAGE_REPLACED"/&gt;
                  &lt;action android:name="android.intent.action.PACKAGE_RESTARTED"/&gt;     
              &lt;/intent-filter&gt;
          &lt;/receiver&gt;
  </code></pre>