background-service-lib icon indicating copy to clipboard operation
background-service-lib copied to clipboard

Service close when application is close on appo F9

Open yaseenyahya opened this issue 5 years ago • 1 comments

Service close when application is close on appo F9.. can you help me..

yaseenyahya avatar Apr 07 '19 07:04 yaseenyahya

Hi there

To ensure the service does not close when the Activity that's linked to it closes, you'll need to override the default Application class and use it to start the Service when the Application starts. This way the Service started independently of the Activity.

Don't forget to also set this Application class as the android:name for your Application in the manifest file.

There's some sample code in the documentation for using the Application class to start the Service:

public class DemonstrationApp extends Application {
  @Override
  public void onCreate() {
    super.onCreate();
    Intent i = new Intent(this, DemonstrationService.class);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
      startForegroundService(i);
    } else {
      startService(i);
    }
  }
}

instantiator avatar Apr 09 '19 14:04 instantiator