Search code examples
androidandroid-widget

Restrict Android Widget to one instance per device


How could I restrict Android widgets in a way that only one instance can be created by the user at all times?

A possible way is to store a SharedPreference including a counter variable and crash, if the count is 1, but obviously I'm not in favor of that solution. ;-)


Solution

  • How could I restrict Android widgets in a way that only one instance can be created by the user at all times?

    You can't.

    However, just because the user asks for multiple instances of your app widget does not mean you have to manage separate data for each. Just ignore the IDs and use the updateAppWidget() method that does not take any IDs.