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;








0















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)










share|improve this question






















  • 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

















0















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)










share|improve this question






















  • 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













0












0








0








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)










share|improve this question














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






share|improve this question













share|improve this question











share|improve this question




share|improve this question










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

















  • 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












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
);



);













draft saved

draft discarded


















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















draft saved

draft discarded
















































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.




draft saved


draft discarded














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





















































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







Popular posts from this blog

Save data to MySQL database using ExtJS and PHP [closed]2019 Community Moderator ElectionHow can I prevent SQL injection in PHP?Which MySQL data type to use for storing boolean valuesPHP: Delete an element from an arrayHow do I connect to a MySQL Database in Python?Should I use the datetime or timestamp data type in MySQL?How to get a list of MySQL user accountsHow Do You Parse and Process HTML/XML in PHP?Reference — What does this symbol mean in PHP?How does PHP 'foreach' actually work?Why shouldn't I use mysql_* functions in PHP?

Compiling GNU Global with universal-ctags support Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) Data science time! April 2019 and salary with experience The Ask Question Wizard is Live!Tags for Emacs: Relationship between etags, ebrowse, cscope, GNU Global and exuberant ctagsVim and Ctags tips and trickscscope or ctags why choose one over the other?scons and ctagsctags cannot open option file “.ctags”Adding tag scopes in universal-ctagsShould I use Universal-ctags?Universal ctags on WindowsHow do I install GNU Global with universal ctags support using Homebrew?Universal ctags with emacsHow to highlight ctags generated by Universal Ctags in Vim?

Add ONERROR event to image from jsp tldHow to add an image to a JPanel?Saving image from PHP URLHTML img scalingCheck if an image is loaded (no errors) with jQueryHow to force an <img> to take up width, even if the image is not loadedHow do I populate hidden form field with a value set in Spring ControllerStyling Raw elements Generated from JSP tagds with Jquery MobileLimit resizing of images with explicitly set width and height attributeserror TLD use in a jsp fileJsp tld files cannot be resolved