title: How to make continue running background services in android pie?
body: <p>I want to play background music when application was killed from recent task menu in android studio.</p>
  
  <p>I have tried using background services...lower devices application worked fine but in android pie after 5 sec song will stopped.</p>
  
  <pre><code>public class Myservice extends Service  {
  MediaPlayer mediaPlayer;
  
  @Nullable
  @Override
  public IBinder onBind(Intent intent) {
      return null;
  }
  
  @Override
  public void onCreate() {
  
      Toast.makeText(this, "service started successfully", Toast.LENGTH_SHORT).show();
      mediaPlayer = MediaPlayer.create(this, animal);
      mediaPlayer.setLooping(false);
  
      super.onCreate();
  }
  
  @Override
  public void onStart(Intent intent, int startId) {
  
      Toast.makeText(this, "Mediaplayer started", Toast.LENGTH_SHORT).show();
      mediaPlayer.start();
  
      super.onStart(intent, startId);
  }
  
  @Override
  public void onDestroy() {
  
      mediaPlayer.stop();
  
      }
  }
  </code></pre>