handle socket connection in background service for api 28











up vote
0
down vote

favorite












Before api 28 i can simply start a background service and continuously listen to a socket connection for any incoming data
however in recent changes in api 28 as shown here https://developer.android.com/about/versions/oreo/background#services
i can no longer start a background service in android 9 unless it covers only one of the following case




Under certain circumstances, a background app is placed on a temporary
whitelist for several minutes. While an app is on the whitelist, it
can launch services without limitation, and its background services
are permitted to run. An app is placed on the whitelist when it
handles a task that's visible to the user, such as:



Handling a high-priority Firebase Cloud Messaging (FCM) message.

Receiving a broadcast, such as an SMS/MMS message.
Executing a PendingIntent from a notification.
Starting a VpnService before the VPN app promotes itself to the
foreground.




The only option i found is to start service as a foreground .
I already found some alternative like using JobScheduler or WorkManger but i don't think they can cover my requirements



so my question is there any other way to listen for a socket connection that targets android 9 (api 28) other than using foreground service?










share|improve this question
























  • what do you mean what is the best practice? There is only one option and you already know what that is
    – Tim Castelijns
    Nov 7 at 11:48












  • u mean foreground service?
    – has19
    Nov 7 at 11:49















up vote
0
down vote

favorite












Before api 28 i can simply start a background service and continuously listen to a socket connection for any incoming data
however in recent changes in api 28 as shown here https://developer.android.com/about/versions/oreo/background#services
i can no longer start a background service in android 9 unless it covers only one of the following case




Under certain circumstances, a background app is placed on a temporary
whitelist for several minutes. While an app is on the whitelist, it
can launch services without limitation, and its background services
are permitted to run. An app is placed on the whitelist when it
handles a task that's visible to the user, such as:



Handling a high-priority Firebase Cloud Messaging (FCM) message.

Receiving a broadcast, such as an SMS/MMS message.
Executing a PendingIntent from a notification.
Starting a VpnService before the VPN app promotes itself to the
foreground.




The only option i found is to start service as a foreground .
I already found some alternative like using JobScheduler or WorkManger but i don't think they can cover my requirements



so my question is there any other way to listen for a socket connection that targets android 9 (api 28) other than using foreground service?










share|improve this question
























  • what do you mean what is the best practice? There is only one option and you already know what that is
    – Tim Castelijns
    Nov 7 at 11:48












  • u mean foreground service?
    – has19
    Nov 7 at 11:49













up vote
0
down vote

favorite









up vote
0
down vote

favorite











Before api 28 i can simply start a background service and continuously listen to a socket connection for any incoming data
however in recent changes in api 28 as shown here https://developer.android.com/about/versions/oreo/background#services
i can no longer start a background service in android 9 unless it covers only one of the following case




Under certain circumstances, a background app is placed on a temporary
whitelist for several minutes. While an app is on the whitelist, it
can launch services without limitation, and its background services
are permitted to run. An app is placed on the whitelist when it
handles a task that's visible to the user, such as:



Handling a high-priority Firebase Cloud Messaging (FCM) message.

Receiving a broadcast, such as an SMS/MMS message.
Executing a PendingIntent from a notification.
Starting a VpnService before the VPN app promotes itself to the
foreground.




The only option i found is to start service as a foreground .
I already found some alternative like using JobScheduler or WorkManger but i don't think they can cover my requirements



so my question is there any other way to listen for a socket connection that targets android 9 (api 28) other than using foreground service?










share|improve this question















Before api 28 i can simply start a background service and continuously listen to a socket connection for any incoming data
however in recent changes in api 28 as shown here https://developer.android.com/about/versions/oreo/background#services
i can no longer start a background service in android 9 unless it covers only one of the following case




Under certain circumstances, a background app is placed on a temporary
whitelist for several minutes. While an app is on the whitelist, it
can launch services without limitation, and its background services
are permitted to run. An app is placed on the whitelist when it
handles a task that's visible to the user, such as:



Handling a high-priority Firebase Cloud Messaging (FCM) message.

Receiving a broadcast, such as an SMS/MMS message.
Executing a PendingIntent from a notification.
Starting a VpnService before the VPN app promotes itself to the
foreground.




The only option i found is to start service as a foreground .
I already found some alternative like using JobScheduler or WorkManger but i don't think they can cover my requirements



so my question is there any other way to listen for a socket connection that targets android 9 (api 28) other than using foreground service?







android background-service






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 7 at 12:04

























asked Nov 7 at 11:46









has19

340416




340416












  • what do you mean what is the best practice? There is only one option and you already know what that is
    – Tim Castelijns
    Nov 7 at 11:48












  • u mean foreground service?
    – has19
    Nov 7 at 11:49


















  • what do you mean what is the best practice? There is only one option and you already know what that is
    – Tim Castelijns
    Nov 7 at 11:48












  • u mean foreground service?
    – has19
    Nov 7 at 11:49
















what do you mean what is the best practice? There is only one option and you already know what that is
– Tim Castelijns
Nov 7 at 11:48






what do you mean what is the best practice? There is only one option and you already know what that is
– Tim Castelijns
Nov 7 at 11:48














u mean foreground service?
– has19
Nov 7 at 11:49




u mean foreground service?
– has19
Nov 7 at 11:49












1 Answer
1






active

oldest

votes

















up vote
0
down vote













Nice Question. I have also survived with service. Foreground service also not a better solution for Android 9. Cause due to system resource circumstances foreground service also can be killed.



Better you can use WorkManager. It will give you a nice flavor.



Give it to a try.






share|improve this answer





















  • i am not sure but i don't think i can use workmanager for a long running task like background service
    – has19
    Nov 7 at 12:47











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














 

draft saved


draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53188840%2fhandle-socket-connection-in-background-service-for-api-28%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
0
down vote













Nice Question. I have also survived with service. Foreground service also not a better solution for Android 9. Cause due to system resource circumstances foreground service also can be killed.



Better you can use WorkManager. It will give you a nice flavor.



Give it to a try.






share|improve this answer





















  • i am not sure but i don't think i can use workmanager for a long running task like background service
    – has19
    Nov 7 at 12:47















up vote
0
down vote













Nice Question. I have also survived with service. Foreground service also not a better solution for Android 9. Cause due to system resource circumstances foreground service also can be killed.



Better you can use WorkManager. It will give you a nice flavor.



Give it to a try.






share|improve this answer





















  • i am not sure but i don't think i can use workmanager for a long running task like background service
    – has19
    Nov 7 at 12:47













up vote
0
down vote










up vote
0
down vote









Nice Question. I have also survived with service. Foreground service also not a better solution for Android 9. Cause due to system resource circumstances foreground service also can be killed.



Better you can use WorkManager. It will give you a nice flavor.



Give it to a try.






share|improve this answer












Nice Question. I have also survived with service. Foreground service also not a better solution for Android 9. Cause due to system resource circumstances foreground service also can be killed.



Better you can use WorkManager. It will give you a nice flavor.



Give it to a try.







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 7 at 12:25









Al-Amin

1428




1428












  • i am not sure but i don't think i can use workmanager for a long running task like background service
    – has19
    Nov 7 at 12:47


















  • i am not sure but i don't think i can use workmanager for a long running task like background service
    – has19
    Nov 7 at 12:47
















i am not sure but i don't think i can use workmanager for a long running task like background service
– has19
Nov 7 at 12:47




i am not sure but i don't think i can use workmanager for a long running task like background service
– has19
Nov 7 at 12:47


















 

draft saved


draft discarded



















































 


draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53188840%2fhandle-socket-connection-in-background-service-for-api-28%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







這個網誌中的熱門文章

Xamarin.form Move up view when keyboard appear

Post-Redirect-Get with Spring WebFlux and Thymeleaf

Anylogic : not able to use stopDelay()