Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6131189
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T16:56:43+00:00 2026-05-23T16:56:43+00:00

I’m sure this is an easy answer, but it’s driving me crazy and I’m

  • 0

I’m sure this is an easy answer, but it’s driving me crazy and I’m hoping someone can just put me out of my misery.

I have an android activity, widget and service. The service runs sound in the background, either for a set amount of time or continuously. Because I want the sound to run until stop is hit, I don’t have a stopSelf() method in the service. This was all fine and dandy with the activity because I had it startService on play, and stopService on stop. Now I want to throw a widget in this latest update. So here’s where I’m stuck. Because it’s a broadcast receiver, I’m very limited in what it can do. I can call context.stopService, but I only want to stop the service when the button is pressed. I can only find a way to set an onClickListener with a pendingIntent.

In my service’s onStartCommand() method, I read the “loops” extra from the incoming intent. So I tried just passing in a value of zero, but for some reason it doesn’t seem to read it. I know the onStartCommand() is being called in the service because the music is playing, but regardless of what extra I throw on the intent, it doesn’t seem to read it and I have no idea why. So my question is, what is the best strategy to use to stop a service from a widget’s button? I’m hoping it’s an easy answer, otherwise I guess I could create a new activity or broadcast receiver to handle the button click, but that seems so unnecessary. Any advice would be very much appreciated! Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T16:56:43+00:00Added an answer on May 23, 2026 at 4:56 pm

    The PendingIntent you pass to the button in the Widget should be able to send Intent extras to the service like any other Intent: you should be able to detect that Intent in onStartCommand and then tell the Service to stop the sound and stop itself. Hard to tell what else you might be doing wrong without some code.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
Does anyone know how can I replace this 2 symbol below from the string
I have just tried to save a simple *.rtf file with some websites and
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a jquery bug and I've been looking for hours now, I can't
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.