title: how to run background service forever in android
body: <p>I am trying to change the wallpaper according to the time set by the user, it is working fine for any long time when I run it on the emulator and also on mobile by connecting it through USB. But when I generated Signed apk and installing on it the same mobile it is not working, the app is terminating after some while.</p>
  
  <p>Can anyone help me, please?</p>
  
  <p>This is my manifest file:</p>
  
  <pre><code>&lt;uses-permission android:name="android.permission.SET_WALLPAPER" /&gt;
  &lt;uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /&gt;
  &lt;uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /&gt;
  &lt;uses-permission android:name="android.permission.READ_INTERNAL_STORAGE" /&gt;
  &lt;uses-permission android:name="android.permission.WAKE_LOCK" /&gt;
  &lt;uses-permission android:name="android.permission.SET_WALLPAPER_HINTS"/&gt;
  
  &lt;application
      android:allowBackup="true"
      android:icon="@mipmap/ic_launcher"
      android:label="@string/app_name"
      android:roundIcon="@mipmap/ic_launcher_round"
      android:supportsRtl="true"
      android:theme="@style/AppTheme"
      tools:ignore="GoogleAppIndexingWarning"&gt;
      &lt;activity android:name=".MainActivity"&gt;
          &lt;intent-filter&gt;
              &lt;action android:name="android.intent.action.MAIN" /&gt;
  
              &lt;category android:name="android.intent.category.LAUNCHER" /&gt;
          &lt;/intent-filter&gt;
      &lt;/activity&gt;
  
      &lt;service android:name=".WllPaper" /&gt;
      &lt;service android:name=".MyThreadOne"
          android:enabled="true"/&gt;
      &lt;receiver android:name=".SensorRestarterBroadcastReceiver"
          android:enabled="true"
          android:exported="true"
          android:label="RestartServiceWhenStopped"&gt;
  
          &lt;intent-filter&gt;
  
              &lt;action android:name="ac.in.ActivityRecongnition.RestartSensor"/&gt;
          &lt;/intent-filter&gt;
      &lt;/receiver&gt;
      &lt;service android:name=".NewThreadClass"/&gt;
      &lt;activity android:name=".NewWallpaper"/&gt;
  
  
      &lt;meta-data
          android:name="preloaded_fonts"
          android:resource="@array/preloaded_fonts" /&gt;
  &lt;/application&gt;
  </code></pre>
  
  <p></p>