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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T16:48:27+00:00 2026-06-15T16:48:27+00:00

I have a code base that has a working widget. The basic structure of

  • 0

I have a code base that has a working widget. The basic structure of this is

MyAppWidget extends AppWidgetProvider
MyWidgetService extends IntentService

MyWidgetService updates MyAppWidget and all was well until I decided to turn my app into a library to create a “free / pro” combo from the same code base. Now I have something like this

com.example.myapp.free.MyAppWidget extends com.example.myapp.library.MyAppWidget
com.example.myapp.pro.MyAppWidget extends com.example.myapp.library.MyAppWidget
com.example.myapp.library.MyAppWidget extends AppWidgetProvider
com.example.myapp.library.MyWidgetService extends IntentService

MyWidgetService runs a MyAppWidget.update() method in order to update the display.

In this case, the widgets have minor tweaks to adjust for the version of the app and everything displays fine, but MyWidgetService doesn’t update the widgets.

I’ve verified that MyWidgetService actually runs as scheduled but it doesn’t know what update method to call. As it stands MyWidgetService will call com.example.myapp.library.MyAppWidget.update() instead of the pro or free versions.

I was able to pass down a flag and tell it which widget class it is, but that means my parent class (library MyWidgetService) needs to know details about the pro / free classes to update. This breaks the proper object orientated model.

My question is, what is the proper way to communicate which widget class should be updated?

Since this is a difficult thing to explain, below are some skeleton details of my classes in case it helps explain things.

Any help is appreciated.

Library MyWidgetService

public class MyWidgetService extends IntentService {

    public MyWidgetService() {
        super(MyWidgetService.class.getSimpleName());
    }

    @Override
    protected void onHandleIntent(Intent intent) {
        // this calls the update method of the widget
        // but it doesn't know which object to call
        MyAppWidget.update();
        scheduleNextUpdate();
    }

    @Override
    public int onStartCommand(Intent intent, int flags, int startId) {
        super.onStartCommand(intent, flags, startId);       
        return START_STICKY;
    }

    private void scheduleNextUpdate() {         
        // schedule next time for the service to work
    }   
}

Library MyAppWidget

public class MyAppWidget extends AppWidgetProvider {

    @Override
    public void onEnabled(Context context) {
        super.onEnabled(context);
        Intent intent = new Intent(context, MyWidgetService.class);
        context.startService(intent);
    }

    public static void update() {
        // update widget display
    }
}

Free MyAppWidget that extends Library MyAppWidget

public class MyAppWidget extends com.example.myapp.library.MyAppWidget {

    @Override
    public void onEnabled(Context context) {
        super.onEnabled(context);
        // setup free widget
        // what can I do here to pass down to the service
        // to make sure it updates this widget class
    }
}

Free app manifest

<!-- use the extended widget from com.example.myapp.free -->
<receiver
    android:name=".MyWidgetApp"
    android:label="@string/clock_widget_name">
    <intent-filter>
        <action android:name="android.appwidget.action.APPWIDGET_ENABLED" />
        <action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
    </intent-filter>

    <meta-data
        android:name="android.appwidget.provider"
        android:resource="@xml/clock_widget" />
</receiver>
<!-- use the service from the library project -->
<service android:name="com.example.myapp.library.MyWidgetService" />
  • 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-15T16:48:29+00:00Added an answer on June 15, 2026 at 4:48 pm

    I was able to pass down a flag and tell it which widget class it is, but that means my parent class (library MyWidgetService) needs to know details about the pro / free classes to update. This breaks the proper object orientated model.

    Instead of passing the flag, pass the fully-qualified class name, and use reflection to access it.

    Or, make update() be an instance method, triggered by a custom broadcast action and dispatch logic in onReceive(). Then have the service send a matching broadcast.

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

Sidebar

Related Questions

I have a C++ code base that has been working for a long time.
In the code base I'm working in there have a method that has the
I have a code base that has been used as an ASP.Net web application.
I have this program that should execute a piece of code base on the
I am currently working on a code base, that has never had any unit
I have an iPad application that has a base image UIImageView (in this case
I am working on a rather large code base that has a bit of
I have a code-base that I'm looking to split up and add to by
I have a code base that deals with simulation of certain data. It involves
is there any development environments that allow you to have one code base that

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.