Languages

Menu
Sites
Language
Multiple widgets

Hi

As far as I've seen its possible to add multiple instances of the same widget. How can I distinguish between them? What I try to do is something like that:

1) the user adds a widget which is then in the setup mode

2) when the users taps on it, the main app opens and the user can choose what that widget should do. This information gets stored in a central file

3) when the widget then gets reoloaded it can read that file. If it contains a record for itself, the widgets UI and functionality get created accordingly.

I've got already all of that, but what I need is an id or something that is a) persistent and b) each widget instance has its own. Does that exist?

Responses

9 Replies
Alex Dem

Hi,
If you mean how to determine instances of the same widget: 

The instances of the same widget have its own unique context.
Maybe to determine instanses of widgets on runtime you could use:
use widget_app_get_id(context) with your widget_context_h which comes in all widget_instance_lifecycle_callback_s functions.

Also you could try to register:

widget_app_foreach_context(widget_context_cb, NULL);
//...
bool widget_context_cb(widget_context_h context, void *data)
{
    dlog_print(DLOG_ERROR,LOG_TAG,"widget_context_cb - %s",widget_app_get_id(context));
    return true;
}

which will retrives all existing сontexts of your widget app and you could seperate them.

But maybe I do not understand some details of your problem.
Alexey.

Alex Dem

Also you could use prefernces :
https://developer.tizen.org/development/tutorials/native-application/application-framework/application/preference
to store some data and share it between instances of widget.
Alexey.

Philippe Wechsler

Hi, first the widget instance seemed just fine for my purposes, but it appears that the instance id changes for the same widget if I restart the emulator. Just imagine that I have multiple widgets where each of it represents some information about a different city. Now each widget needs to know to which city it is assigned. And of course if the watch gets restarted, the widgets should remember their city. Is that somehow possible? Or am I missing something with the widget-id?

Alex Dem

Hi,
Maybe I do not understand what your problem?
But if you want to store for every instance of widget some related data , you could store pair key/value ("widget-id"/"city") with preference_set_string/preference_get_string. 
and check it on widget start inside widget_instance_resume (you could use preference_is_existing to check that your key is existed also).
So appropriate data will be assigned on appropriate widget's instance.
I have checked with mobile and was able to restore data saved with preference api after restart. For wearable the same api should be able too.
Alexey.

Philippe Wechsler

Hi,

Yes that would work IFF the widget instance id is persistent. So here what I've done: I've created a simple widget that does nothing else than rendering the widget instance id. This Id looks something like "opt/usr/share/live_magazin/[PACKAGE ID]_725_2619.912842.png" (that looks very strange to me, can that realy be?!?). So far so good, but when the watch gets restarted for example, that id is not the same anymore ("opt/usr/share/live_magazin/[PACKAGE ID]_2362_5591,616211.png")!

Therefore this solutions seems not praticable, as this would imply that the widget would not remember it's city once the watch has been restarted (or only the widget). Am I doing something wrong? Is that really an Widget Instance id?

Thx

Philippe

Alex Dem

Hi,
Ok, I'll check it on Gear 2S also, but on mobile widget's ids are the same after restart.
Alexey.

Alex Dem

Hi, 
Yes , You are right , I have checked with Gear , Widget Id is differnrt after device's restart (I was mistaken, with mobile  there is the same.)
Now it is not quite clear how to determine widget's instance - it's a problem.
Alexey.

Alex Dem

Hi,
Maybe you could try to ask about using https://lists.tizen.org/
dev list here https://lists.tizen.org/listinfo/dev
Alexey.

Philippe Wechsler

​This is just unbelievable!!!! The bug is still there in Tizen 2.3.2! Tizen is absolute crap, it's an absolute disaster. Shame on Samsung!!!