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 8818453
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T05:06:33+00:00 2026-06-14T05:06:33+00:00

Following the example here i created my widget with ease. I then added a

  • 0

Following the example here i created my widget with ease.

I then added a button to my widget, this button should start a service so I added the following code to my WidgetProvider

@Override
public void onEnabled(Context context) {
    Log.e("ERROR", "REMOVE ME"); // TODO remove. This is for eclipse logcat recognition
    RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.widget_layout);

    Intent intent = new Intent(context, RepairService.class);
    PendingIntent pi = PendingIntent.getService(context, 0, intent, 0);
    views.setOnClickPendingIntent(R.id.widget_boost, pi);
}

The code certainly gets called, but service doesn’t get started. I’m sure I have probably missed something with implementation of a service PendingIntent, but I can’t see what. Anyone else know?

  • 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-06-14T05:06:34+00:00Added an answer on June 14, 2026 at 5:06 am

    Well I have managed to fix it

    public class WidgetProvider extends AppWidgetProvider {
    
    @Override
      public void onUpdate(Context context, AppWidgetManager appWidgetManager,
          int[] appWidgetIds) {
    
        Log.e("ERROR", "onUpdate method called");
    
        final int N = appWidgetIds.length;
    
        // Perform this loop procedure for each App Widget that belongs to this provider
        for (int i=0; i<N; i++) {
            int appWidgetId = appWidgetIds[i];
    
            // Create an Intent to launch ExampleActivity
            Intent intent = new Intent(context, UpdateService.class);
            PendingIntent pendingIntent = PendingIntent.getService(context, 0, intent, 0);
            Log("Pending Intent = " + pendingIntent.toString());
    
            // Get the layout for the App Widget and attach an on-click listener to the button
            RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.widget_layout);
            views.setOnClickPendingIntent(R.id.widge, pendingIntent);
    
            // Tell the AppWidgetManager to perform an update on the current App Widget
            appWidgetManager.updateAppWidget(appWidgetId, views);
        }
    
    }
    
    public static class UpdateService extends Service {
    
        @Override
        public void onCreate() {
                  .........
                  .........
               }
    
               // Service stuff here
       }
    }
    

    I am not entirely sure what was wrong with doing it in onEnable. Maybe someone can shed some light as to why.

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

Sidebar

Related Questions

Following the example of writing a custom django-admin command here , I've created the
Consider the following code: (live example here ) $(function() { var wrapper = $(<div
Consider the following example: ( live demo here ) HTML: <div class=board> <div class=row>
I was trying the following example of I/O ports from here . #include<stdio.h> #include<unistd.h>
Following an example in Accelerated C++ , I created a custom STL container, which
I was following this example: http://developer.android.com/resources/tutorials/views/hello-autocomplete.html And I want to know how I can
I created the following example source and am wondering what I need to do
I'm trying to create a menu in Qt following this example http://doc.qt.nokia.com/latest/mainwindows-menus.html but I
I'm following a simple example of how to use the update panel from here
I'm trying to create a ListView with custom ArrayAdapter. Following the example from here.

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.