Not allowed to start service Intent app in on background Unicorn Meta Zoo #1: Why another podcast? Announcing the arrival of Valued Associate #679: Cesar Manara Data science time! April 2019 and salary with experience The Ask Question Wizard is Live!GyroListener created in onCreate() is null in onResume()Show last picture taken in ImageView not workingOpencv crashes when initAsync is calledjava.lang.NullPointerException: error - app is not openingAndroid 8.0: java.lang.IllegalStateException: Not allowed to start service IntentWhy is this connection read-only?app crash on settext() fragment functionHow to pass initial properties in hybrid React-native appIonic Barcode Scanning Process Crash in AndroidActivity Recognition Transition API In Foreground Service
What is a 'Key' in computer science?
Why does Java have support for time zone offsets with seconds precision?
Did war bonds have better investment alternatives during WWII?
Protagonist's race is hidden - should I reveal it?
Israeli soda type drink
What's parked in Mil Moscow helicopter plant?
What is the numbering system used for the DSN dishes?
Does a Draconic Bloodline sorcerer's doubled proficiency bonus for Charisma checks against dragons apply to all dragon types or only the chosen one?
Is there an efficient way for synchronising audio events real-time with LEDs using an MCU?
Why does the Cisco show run command not show the full version, while the show version command does?
`FindRoot [ ]`::jsing: Encountered a singular Jacobian at a point...WHY
What does the black goddess statue do and what is it?
Are these square matrices always diagonalisable?
How was Lagrange appointed professor of mathematics so early?
What is the ongoing value of the Kanban board to the developers as opposed to management
Coin Game with infinite paradox
What were wait-states, and why was it only an issue for PCs?
Could a cockatrice have parasitic embryos?
Processing ADC conversion result: DMA vs Processor Registers
Page Layouts : 1 column , 2 columns-left , 2 columns-right , 3 column
Determinant of a matrix with 2 equal rows
Is it OK if I do not take the receipt in Germany?
Why is arima in R one time step off?
How long can a nation maintain a technological edge over the rest of the world?
Not allowed to start service Intent app in on background
Unicorn Meta Zoo #1: Why another podcast?
Announcing the arrival of Valued Associate #679: Cesar Manara
Data science time! April 2019 and salary with experience
The Ask Question Wizard is Live!GyroListener created in onCreate() is null in onResume()Show last picture taken in ImageView not workingOpencv crashes when initAsync is calledjava.lang.NullPointerException: error - app is not openingAndroid 8.0: java.lang.IllegalStateException: Not allowed to start service IntentWhy is this connection read-only?app crash on settext() fragment functionHow to pass initial properties in hybrid React-native appIonic Barcode Scanning Process Crash in AndroidActivity Recognition Transition API In Foreground Service
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
This is one of the most annoying android errors ever.
I've one service in my app that must run always that user is running the app.
Since android doesn't allow me to have a background service always on, and to have a foreground service on i must keep an annoying notification to the user. I turn on and turn off the service as the user goes background or foreground.
So, In a "pseudocode" I do:
app went background?
is the service working? yes! -> keep running it : no! -> turn off
app went foreground?
is the service on? yes! -> do nothing : no! -> turn service on
The problem is when the user goes foreground and background very quickly.
In this situation the app call the method startService()
to start the service, but before the method finishes user goes background then i get:
Caused by java.lang.IllegalStateException: Not allowed to start service Intent cmp=com.tomatedigital.instagramgiveawaywinner/com.tomatedigital.giveawaymaster.service.MyService : app is in background uid UidRecord78dfb43 u0a139 TPSL bg:+2m52s319ms idle change:cached procs:1 seq(203,203,203)
at android.app.ContextImpl.startServiceCommon(ContextImpl.java:1592)
at android.app.ContextImpl.startService(ContextImpl.java:1547)
at android.content.ContextWrapper.startService(ContextWrapper.java:664)
at com.tomatedigital.giveawaymaster.activity.AdsAppCompatActivity.onResume(SourceFile:310)
at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1434)
at android.app.Activity.performResume(Activity.java:7304)
at android.app.ActivityThread.performResumeActivity(ActivityThread.java:3993)
at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:4033)
at android.app.servertransaction.ResumeActivityItem.execute(ResumeActivityItem.java:51)
at android.app.servertransaction.TransactionExecutor.executeLifecycleState(TransactionExecutor.java:145)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:70)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1977)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6923)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:870)
The most annoying think is i can't block user to go background, neither can catch this exception since it is thrown asynchrounously bys some android service wake up routine
HOW CAN I DEAL WITH IT
i would say 0,1% of my users go in this situation (is a few users but is a very annoying error)
android
add a comment |
This is one of the most annoying android errors ever.
I've one service in my app that must run always that user is running the app.
Since android doesn't allow me to have a background service always on, and to have a foreground service on i must keep an annoying notification to the user. I turn on and turn off the service as the user goes background or foreground.
So, In a "pseudocode" I do:
app went background?
is the service working? yes! -> keep running it : no! -> turn off
app went foreground?
is the service on? yes! -> do nothing : no! -> turn service on
The problem is when the user goes foreground and background very quickly.
In this situation the app call the method startService()
to start the service, but before the method finishes user goes background then i get:
Caused by java.lang.IllegalStateException: Not allowed to start service Intent cmp=com.tomatedigital.instagramgiveawaywinner/com.tomatedigital.giveawaymaster.service.MyService : app is in background uid UidRecord78dfb43 u0a139 TPSL bg:+2m52s319ms idle change:cached procs:1 seq(203,203,203)
at android.app.ContextImpl.startServiceCommon(ContextImpl.java:1592)
at android.app.ContextImpl.startService(ContextImpl.java:1547)
at android.content.ContextWrapper.startService(ContextWrapper.java:664)
at com.tomatedigital.giveawaymaster.activity.AdsAppCompatActivity.onResume(SourceFile:310)
at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1434)
at android.app.Activity.performResume(Activity.java:7304)
at android.app.ActivityThread.performResumeActivity(ActivityThread.java:3993)
at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:4033)
at android.app.servertransaction.ResumeActivityItem.execute(ResumeActivityItem.java:51)
at android.app.servertransaction.TransactionExecutor.executeLifecycleState(TransactionExecutor.java:145)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:70)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1977)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6923)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:870)
The most annoying think is i can't block user to go background, neither can catch this exception since it is thrown asynchrounously bys some android service wake up routine
HOW CAN I DEAL WITH IT
i would say 0,1% of my users go in this situation (is a few users but is a very annoying error)
android
It doesn't sound like you need a service if you only want it running while the app is in the foreground. Why not just use a Thread?
– Gavin Wright
Mar 9 at 9:06
read again... i do need a service
– Rafael Lima
Mar 9 at 16:53
The whole point of a service is that it runs when your activity is in the background. But you're only using the service when your app is in the foreground...which means you don't need a service.
– Gavin Wright
Mar 9 at 22:11
Service are used when apps are in background or not running. Why do you want a service when the app is running? I would suggest to change the architecture of your app. Or maybe I am missing something why do you need a service when the app is in FOREGROUND? Threads can handle any tasks that needs to be done when the app is running and in foreground.
– Pronoy Mukherjee
Mar 10 at 3:31
1
read the text... the question isn't if i need or not a service. is how to handle the exception thrown
– Rafael Lima
Mar 11 at 3:12
add a comment |
This is one of the most annoying android errors ever.
I've one service in my app that must run always that user is running the app.
Since android doesn't allow me to have a background service always on, and to have a foreground service on i must keep an annoying notification to the user. I turn on and turn off the service as the user goes background or foreground.
So, In a "pseudocode" I do:
app went background?
is the service working? yes! -> keep running it : no! -> turn off
app went foreground?
is the service on? yes! -> do nothing : no! -> turn service on
The problem is when the user goes foreground and background very quickly.
In this situation the app call the method startService()
to start the service, but before the method finishes user goes background then i get:
Caused by java.lang.IllegalStateException: Not allowed to start service Intent cmp=com.tomatedigital.instagramgiveawaywinner/com.tomatedigital.giveawaymaster.service.MyService : app is in background uid UidRecord78dfb43 u0a139 TPSL bg:+2m52s319ms idle change:cached procs:1 seq(203,203,203)
at android.app.ContextImpl.startServiceCommon(ContextImpl.java:1592)
at android.app.ContextImpl.startService(ContextImpl.java:1547)
at android.content.ContextWrapper.startService(ContextWrapper.java:664)
at com.tomatedigital.giveawaymaster.activity.AdsAppCompatActivity.onResume(SourceFile:310)
at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1434)
at android.app.Activity.performResume(Activity.java:7304)
at android.app.ActivityThread.performResumeActivity(ActivityThread.java:3993)
at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:4033)
at android.app.servertransaction.ResumeActivityItem.execute(ResumeActivityItem.java:51)
at android.app.servertransaction.TransactionExecutor.executeLifecycleState(TransactionExecutor.java:145)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:70)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1977)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6923)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:870)
The most annoying think is i can't block user to go background, neither can catch this exception since it is thrown asynchrounously bys some android service wake up routine
HOW CAN I DEAL WITH IT
i would say 0,1% of my users go in this situation (is a few users but is a very annoying error)
android
This is one of the most annoying android errors ever.
I've one service in my app that must run always that user is running the app.
Since android doesn't allow me to have a background service always on, and to have a foreground service on i must keep an annoying notification to the user. I turn on and turn off the service as the user goes background or foreground.
So, In a "pseudocode" I do:
app went background?
is the service working? yes! -> keep running it : no! -> turn off
app went foreground?
is the service on? yes! -> do nothing : no! -> turn service on
The problem is when the user goes foreground and background very quickly.
In this situation the app call the method startService()
to start the service, but before the method finishes user goes background then i get:
Caused by java.lang.IllegalStateException: Not allowed to start service Intent cmp=com.tomatedigital.instagramgiveawaywinner/com.tomatedigital.giveawaymaster.service.MyService : app is in background uid UidRecord78dfb43 u0a139 TPSL bg:+2m52s319ms idle change:cached procs:1 seq(203,203,203)
at android.app.ContextImpl.startServiceCommon(ContextImpl.java:1592)
at android.app.ContextImpl.startService(ContextImpl.java:1547)
at android.content.ContextWrapper.startService(ContextWrapper.java:664)
at com.tomatedigital.giveawaymaster.activity.AdsAppCompatActivity.onResume(SourceFile:310)
at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1434)
at android.app.Activity.performResume(Activity.java:7304)
at android.app.ActivityThread.performResumeActivity(ActivityThread.java:3993)
at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:4033)
at android.app.servertransaction.ResumeActivityItem.execute(ResumeActivityItem.java:51)
at android.app.servertransaction.TransactionExecutor.executeLifecycleState(TransactionExecutor.java:145)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:70)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1977)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6923)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:870)
The most annoying think is i can't block user to go background, neither can catch this exception since it is thrown asynchrounously bys some android service wake up routine
HOW CAN I DEAL WITH IT
i would say 0,1% of my users go in this situation (is a few users but is a very annoying error)
android
android
asked Mar 9 at 4:51
Rafael LimaRafael Lima
519422
519422
It doesn't sound like you need a service if you only want it running while the app is in the foreground. Why not just use a Thread?
– Gavin Wright
Mar 9 at 9:06
read again... i do need a service
– Rafael Lima
Mar 9 at 16:53
The whole point of a service is that it runs when your activity is in the background. But you're only using the service when your app is in the foreground...which means you don't need a service.
– Gavin Wright
Mar 9 at 22:11
Service are used when apps are in background or not running. Why do you want a service when the app is running? I would suggest to change the architecture of your app. Or maybe I am missing something why do you need a service when the app is in FOREGROUND? Threads can handle any tasks that needs to be done when the app is running and in foreground.
– Pronoy Mukherjee
Mar 10 at 3:31
1
read the text... the question isn't if i need or not a service. is how to handle the exception thrown
– Rafael Lima
Mar 11 at 3:12
add a comment |
It doesn't sound like you need a service if you only want it running while the app is in the foreground. Why not just use a Thread?
– Gavin Wright
Mar 9 at 9:06
read again... i do need a service
– Rafael Lima
Mar 9 at 16:53
The whole point of a service is that it runs when your activity is in the background. But you're only using the service when your app is in the foreground...which means you don't need a service.
– Gavin Wright
Mar 9 at 22:11
Service are used when apps are in background or not running. Why do you want a service when the app is running? I would suggest to change the architecture of your app. Or maybe I am missing something why do you need a service when the app is in FOREGROUND? Threads can handle any tasks that needs to be done when the app is running and in foreground.
– Pronoy Mukherjee
Mar 10 at 3:31
1
read the text... the question isn't if i need or not a service. is how to handle the exception thrown
– Rafael Lima
Mar 11 at 3:12
It doesn't sound like you need a service if you only want it running while the app is in the foreground. Why not just use a Thread?
– Gavin Wright
Mar 9 at 9:06
It doesn't sound like you need a service if you only want it running while the app is in the foreground. Why not just use a Thread?
– Gavin Wright
Mar 9 at 9:06
read again... i do need a service
– Rafael Lima
Mar 9 at 16:53
read again... i do need a service
– Rafael Lima
Mar 9 at 16:53
The whole point of a service is that it runs when your activity is in the background. But you're only using the service when your app is in the foreground...which means you don't need a service.
– Gavin Wright
Mar 9 at 22:11
The whole point of a service is that it runs when your activity is in the background. But you're only using the service when your app is in the foreground...which means you don't need a service.
– Gavin Wright
Mar 9 at 22:11
Service are used when apps are in background or not running. Why do you want a service when the app is running? I would suggest to change the architecture of your app. Or maybe I am missing something why do you need a service when the app is in FOREGROUND? Threads can handle any tasks that needs to be done when the app is running and in foreground.
– Pronoy Mukherjee
Mar 10 at 3:31
Service are used when apps are in background or not running. Why do you want a service when the app is running? I would suggest to change the architecture of your app. Or maybe I am missing something why do you need a service when the app is in FOREGROUND? Threads can handle any tasks that needs to be done when the app is running and in foreground.
– Pronoy Mukherjee
Mar 10 at 3:31
1
1
read the text... the question isn't if i need or not a service. is how to handle the exception thrown
– Rafael Lima
Mar 11 at 3:12
read the text... the question isn't if i need or not a service. is how to handle the exception thrown
– Rafael Lima
Mar 11 at 3:12
add a comment |
0
active
oldest
votes
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',
autoActivateHeartbeat: false,
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55074098%2fnot-allowed-to-start-service-intent-app-in-on-background%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55074098%2fnot-allowed-to-start-service-intent-app-in-on-background%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
It doesn't sound like you need a service if you only want it running while the app is in the foreground. Why not just use a Thread?
– Gavin Wright
Mar 9 at 9:06
read again... i do need a service
– Rafael Lima
Mar 9 at 16:53
The whole point of a service is that it runs when your activity is in the background. But you're only using the service when your app is in the foreground...which means you don't need a service.
– Gavin Wright
Mar 9 at 22:11
Service are used when apps are in background or not running. Why do you want a service when the app is running? I would suggest to change the architecture of your app. Or maybe I am missing something why do you need a service when the app is in FOREGROUND? Threads can handle any tasks that needs to be done when the app is running and in foreground.
– Pronoy Mukherjee
Mar 10 at 3:31
1
read the text... the question isn't if i need or not a service. is how to handle the exception thrown
– Rafael Lima
Mar 11 at 3:12