• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

stop service not working

 
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi im playing around with services as i have not used them before when start button is clicked the service starts but stop service does not work its like ainactivity does not respond then it crashes with no stacktrace anyone have any idea? thanks




service


allso there is not taskbar icon on device to show a service is running? I think there should be
 
Ranch Hand
Posts: 606
11
Android Python Open BSD VI Editor Slackware
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Some introductory mistake and then the solution:

introductory mistakes
A class should be started with a capital letter as

public class runner

, is a Java important convention, in my opinion.

Also you may not want use a generic name  as "runner", even if you are playing with the code a class should indicate what is doing, even a generic "MyService" would do better

To debug your code you do not want to just use a "Toast" but adding  

Final introductory consideration you may like also  WorkManager, instead of Service. It would land you easier to a job, and is much easier to manage than a Service across all the changes in the Android ecosystem that came in the years.

You say is crashing without stacktrace, do you have the latest  stable android studio version, the electric? Did you add the service to the manifest? Did you try the option invalidate cache, sometimes does wonders in these cases.

solution
first of all a Service differently by the easier IntentService runs on default on the main thead causing ANR application not responsive. So you should at least run it into a thread. then you are setting a boolean ALWAYS true, is normal that does not work, because the sequence of the program is running the service indefinetely, and the click in the view  when you stop is never gonna be recognized

use this

and

 
Saloon Keeper
Posts: 27719
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There is a "taskbar" in Android. At present, if my memory works, you can see the running apps by double-clicking the center system button at the bottom of the screen. It only shows apps with GUI interfaces and since some apps run full-screen, if you have a "soft" system button set you may have to tweak a bit to get the buttons to display/click.

If you need more details, the Control Panel apps display can help and even lower-level info can be obtained if you go to the Store and install one of the system monitoring apps.
 
john bean
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for replies yeah i was doing it all wrong hit a few youtube videos on services have a bit of a better idea now thanks for the code very helpful
 
Giovanni Montano
Ranch Hand
Posts: 606
11
Android Python Open BSD VI Editor Slackware
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

john bean wrote:Thanks for replies yeah i was doing it all wrong hit a few youtube videos on services have a bit of a better idea now thanks for the code very helpful


glad it helped please check the boolean state also in the second example
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic