How to keep an IntentService running even when app is closed?

fergaral

In my Android app I start an IntentService from within an Activity by calling

startService(new Intent(this, MyService.class));

And it works like a charm. I can move between Activies, press the Home button to switch to other apps... and it's still working. But if I remove my app from the recents screen, my service is stopped. How can I avoid this? In other words, how can I keep my service running even if my app is closed from recent apps?

My service code is as follows:

public class MyService extends IntentService {

public MyService() {
    super("MyService");
}

@Override
protected void onHandleIntent(Intent intent) {
    //Here I run a loop which takes some time to finish
}

}
Stan

IntentService is not running all the time but it works on Intent base. You send, lets say a command to do (do some job), using Intent and service executes that job and stops itself after that waiting for other Intent.
You should use usual Service instead of IntentService to achive your goal. Service should be configured as START_STICKY.

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

分類Dev

Keep broadcast receiver running when activity and/or app is closed?

分類Dev

Keeping a Java app running when SSH is closed on Google Cloud

分類Dev

How to stop Android service when app is closed

分類Dev

how to keep running the loop in python even after a KeyError

分類Dev

Is it possible to have a count down timer continue running even after the user has closed the app

分類Dev

VLC is still running even I closed it already. How to I close it?

分類Dev

How to keep XMPP connection alive in the IOS App when app in background?

分類Dev

How to keep a remote X11 app running after disconnecting SSH?

分類Dev

how to fix error "No task registered for key RNFirebaseBackgroundMessage" when my app is closed for getting fcm message

分類Dev

How to fix notification not showing up when app is running?

分類Dev

Android - Running a IntentService multiple times

分類Dev

How can I avoid my program to keep running when I close my main frame?

分類Dev

Is it possible to keep a socket alive even after closing the app?

分類Dev

How to target app releases in closed tracks to organizations?

分類Dev

How to keep angular PWA running in doze mode

分類Dev

How to keep zsh running after command execution?

分類Dev

How to keep open Tkcalendar after running code

分類Dev

Thread, Asynctask or intentService for my app?

分類Dev

Push Notifications don't vibrate when app is closed

分類Dev

Detect iOS device battery level when app is closed

分類Dev

How to keep items in cart even after refresh using vuex

分類Dev

How to keep an element hidden even before document.ready?

分類Dev

Connection not closed even if call is verified

分類Dev

Mongo::Error::NoServerAvailable when running Rails app

分類Dev

Disable screen lock when Cordova app is running

分類Dev

Encoding issue when running Gradle app distributions

分類Dev

Beacon Notification when the app is not running on Android

分類Dev

How to set build .env variables when running create-react-app build script?

分類Dev

How to authenticate programmatically when running an Apps Script Web App from another Apps Script project

Related 関連記事

  1. 1

    Keep broadcast receiver running when activity and/or app is closed?

  2. 2

    Keeping a Java app running when SSH is closed on Google Cloud

  3. 3

    How to stop Android service when app is closed

  4. 4

    how to keep running the loop in python even after a KeyError

  5. 5

    Is it possible to have a count down timer continue running even after the user has closed the app

  6. 6

    VLC is still running even I closed it already. How to I close it?

  7. 7

    How to keep XMPP connection alive in the IOS App when app in background?

  8. 8

    How to keep a remote X11 app running after disconnecting SSH?

  9. 9

    how to fix error "No task registered for key RNFirebaseBackgroundMessage" when my app is closed for getting fcm message

  10. 10

    How to fix notification not showing up when app is running?

  11. 11

    Android - Running a IntentService multiple times

  12. 12

    How can I avoid my program to keep running when I close my main frame?

  13. 13

    Is it possible to keep a socket alive even after closing the app?

  14. 14

    How to target app releases in closed tracks to organizations?

  15. 15

    How to keep angular PWA running in doze mode

  16. 16

    How to keep zsh running after command execution?

  17. 17

    How to keep open Tkcalendar after running code

  18. 18

    Thread, Asynctask or intentService for my app?

  19. 19

    Push Notifications don't vibrate when app is closed

  20. 20

    Detect iOS device battery level when app is closed

  21. 21

    How to keep items in cart even after refresh using vuex

  22. 22

    How to keep an element hidden even before document.ready?

  23. 23

    Connection not closed even if call is verified

  24. 24

    Mongo::Error::NoServerAvailable when running Rails app

  25. 25

    Disable screen lock when Cordova app is running

  26. 26

    Encoding issue when running Gradle app distributions

  27. 27

    Beacon Notification when the app is not running on Android

  28. 28

    How to set build .env variables when running create-react-app build script?

  29. 29

    How to authenticate programmatically when running an Apps Script Web App from another Apps Script project

ホットタグ

アーカイブ