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

  • Home
  • SEARCH
  • 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 3989370
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T06:21:55+00:00 2026-05-20T06:21:55+00:00

What I am trying to do is once the AppWidget is removed from the

  • 0

What I am trying to do is once the AppWidget is removed from the homescreen of the user’s Android phone, I want to stop the background service that Updates the AppWidget.

Here is the code that I am using…don’t understand whats wrong?

@Override
 public void onDeleted(Context context, int[] appWidgetIds){
 Intent serviceIntent = new Intent(context, UpdateService.class);
 context.stopService(serviceIntent);
 super.onDeleted(context, appWidgetIds);
}

Any ideas? Thanks for the help.

  • 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-20T06:21:55+00:00Added an answer on May 20, 2026 at 6:21 am

    After a lot of Research I finally fixed it. My goal here was to stop the background service if all AppWidget instances are removed from the screen.

    This is what did it…

    1. Used shared preferences to toggle 1 and 0. SharePref toggled to 1 when the very first instance of the widget is put on the screen by the user. It is toggled back to 0 when the last instance of the App widget is removed from the screen.

    2. @Override OnReceive method in the Service. Listen for these broadcasts – AppWidget Enabled (broadcast when the very first instance of the widget is put on the screen) , AppWidget Disabled (broadcast by the OS when the very last instance of the widget is removed from the screen)
      When AppWidget Disabled is broadcast call the overridden method OnDisabled method.

    3.In @Override OnDisabled method call stopService. Works perfect.

    Remember the difference between OnDeleted and OnDisabled. OnDeleted is called when an instance of the widget is removed, it doesn’t mean that the widget being deleted is the last one. I wanted my service to still run even if there was a single widget instance on the screen.

    *Also if you do not want to do all of the above and let Android take care of the Service etc…use IntentService. **

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

Sidebar

Related Questions

I am trying to convert a VISUAL USER OBJECT that was once embedded on
From the example in my Fiddle you will see that I'm trying to once
hi all i'm trying to perform an action once the user double clicks on
I'm trying to add a class (.active) to a text field once the user
So I'm trying to perform a couple inserts at once that are kind of
I'm trying to prompt the user (once, I record it) to upgrade the iphone
I am trying to design an active object of sorts that once created, essentially
Im trying to remove a class once the user hovers over a link. Here
I'm trying to get contact data once a contact name has been clicked from
I'm trying to limit user's posts to once a day, I was thinking about

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.