0

I want to limit the number of Widget instances of my Widget application that the user is able to start. In fact, for my case it only makes sense to have one.

In the Samsung Gear 2 device, the music player widget has the behaviour I want. Actually when you start this widget, it is not showed again in the Widget list. This would be perfect!

The Schedule Widgets also have this behaviour. There are project samples for the music player and for the Schedule widgets but in the samples this behaviour does not happen.

Any suggestions?

peterg
  • 71
  • 5

1 Answers1

0

I found here the solution: https://developer.tizen.org/zh-hans/forums/native-application-development/limit-number-widget?langswitch=zh-hans

We can do it programatically by adding a variable to count the widget's instances

int instance_count =0;

Then in the widget instance create callback we check the variable and increment it if there is only one instance or return error if it already has one instance created

static int
_on_create_cb(widget_context_h context, bundle *content, int w, int h, void *user_data) {

    if(instance_count >0) return WIDGET_ERROR_ALREADY_EXIST;
    instance_count++;

    return WIDGET_ERROR_NONE;
}

In the destroy callback we decrement the counter

static int
_on_destroy_cb(widget_context_h context, widget_app_destroy_type_e reason, bundle *content, void *user_data) {
    instance_count--;
    return WIDGET_ERROR_NONE;
}

This is not the perfect solution because it still allows the user to select the widget from the list, but it works. I also tested crashing the app on purpose and this solution works. When the app crashes the _on_destroy_cb is not called, but the instance_count is reset to 0 anyway.

peterg
  • 71
  • 5
  • In my opinion, it would be better if there's any option for the developers to hide the installed widget from the widget board after creating a single instance of it. But unfortunately, I couldn't find any! – Shaswati Saha Nov 30 '16 at 09:00
  • 1
    Yes I agree. It would be much better if that option exists. Couldn't find also. – peterg Dec 16 '16 at 21:46