title: how to create a PERMANENT background service on android
body: <p>I'm having a nightmare trying to create a simple background service on android that runs permanently.</p>
  
  <p>This service will be doing some background tasks like pool users social media and show notification so it requires only one user interaction (login) after that should be able to run forever until the end of the days....</p>
  
  <p>but it is not happening</p>
  
  <p>this is my manifest:</p>
  
  <pre><code>&lt;service
          android:name=".service.MyService"
          android:description="@string/serviceDescription"
          android:directBootAware="false"
          android:enabled="true"
          android:exported="false"
          android:icon="@drawable/ic_logo"
          android:label="@string/serviceLabel"/&gt;
  </code></pre>
  
  <p>I start service on <code>Application onCreate()</code></p>
  
  <pre><code>    if (MyService.getInstance() == null) {
          Intent intent = new Intent(this, MyService.class);
          startService(intent);
      }
  </code></pre>
  
  <p>service:  </p>
  
  <pre><code>public void onCreate() {
          super.onCreate();
          this.workDone = 0;
  
          this.workerMap = new HashMap&lt;User.UserData, Worker&gt;(3);
          this.listeners = new HashMap&lt;Worker, Worker.WorkerListener&gt;(3);
          this.usernames = new HashMap&lt;APIFacade, List&lt;String&gt;&gt;(3);
  
          this.threadPool = Executors.newFixedThreadPool(3);
          INSTANCE = this;
  
      }
  </code></pre>
  
  <p>ABSOLUTELLY NOWHERE IN MY CODE I CALL STOPSERVICE NOR STOPSELF</p>
  
  <p>so why i'm getting nullpointerexception in some random situations?</p>
  
  <p>someone even told me to do the bellow code to force android to "restart" service</p>
  
  <pre><code>  @Override
      public int onStartCommand(Intent intent, int flags, int startId) {
          return START_STICKY;
      }
  </code></pre>
  
  <p>can someone please help me... i'm getting really stressed with this problem</p>
  
  <p>my app has over 1000 daily users and around 10% of them "find a way" to make nullpointerexception when using the service</p>