Widgets disappear after updating the application using the library

I have 2 versions of the application, free and paid, but they save the code separately. I finally moved the code to a library that both are referencing to make code support easier.

I found that changing AppwidgetProvider caused the launcher to remove all existing widgets, so I moved these classes from the library to keep the provider the same so that users do not have to recreate their widgets. The launcher no longer removes widgets, but instead they simply do not appear after the update.

If I call AppWidgetManager.getAppWidgetIds for the component name, as always, appwidgetid still exists. The appwidgetprovider application and service are still called to update the widget, and /data/system/appwidgets.xml still shows the widget, but the launcher does not display it.

This is not that it is invisible, since a long press on the location of the widget brings up a selection of wallpapers. I can create new widgets just fine, but I don’t want to upset users by asking them to recreate their widgets. Logs do not display errors triggered by the launcher or AppwidgetService .

Any ideas why the widget stops rendering after updating? This has something to do with moving most of the code to a separate library. Thanks!

Edit: I am testing an emulator, api level 15, stock launcher

+4
source share
1 answer

Ok, I found a solution, but I feel sick for having ...

After reading how the classes declared in the manifest should never change, I went and created each class in the manifest as a class in the application, expanding the corresponding class in the library. Then I had to change every intention to include the correct class using forName. So an example of this scenario is:

application package: com.sample.package

Activity: MyActivity

library: com.sample.package.core

Activity: MyActivity

The application has the MyActivity and MyActivity in the library. MyActivity in the application simply extends com.sample.package.core.MyActivity.

Then any entry ...

 new Intent(context, MyActivity.class) 

... the library should become ...

 new Intent(context, Class.forName(context.getPackageName() + "." + MyActivity.class.getSimpleName()); 

If there is a way to do this through the manifest, please let me know!

0
source

All Articles