android - logging to a database when user clicks on a widget -


i have widget displays analog clock. the widget write database time when user clicks on widget. i've got databasehelper class , have activity displays screen showing current date , time , writes time database.

i followed tutorial here: analog clock tutorial , ended this:

public void onreceive(context context, intent intent) {     string action = intent.getaction();     if (appwidgetmanager.action_appwidget_update.equals(action))     {         remoteviews views = new remoteviews(context.getpackagename(), r.layout.widget);         this.mintent = new intent(context, askthetime.class);         pendingintent pendingintent = pendingintent.getactivity(context, 0, mintent, 0);         views.setonclickpendingintent(r.id.widget, pendingintent);          appwidgetmanager.getinstance(context).updateappwidget(intent.getintarrayextra(appwidgetmanager.extra_appwidget_ids), views);     } } 

the askthetime class extends activity , logs database in oncreate(). means displays time when widget started - not when clicked. (i guess because i'm starting pendingintent) i'm not sure if should put database write in method or if should using intents sort of thing widgets. pointers great! i've @ several tutorials intents none of them seem clear me.

when widget pressed, os activates pending intent set on widget.

it looks opening activity askthetime when widget pressed.

so problem askthetime might have been created when widget pressed, oncreate() isn't called again.

what try doing logging in onstart() or onresume() instead of, or in addition to, oncreate() inside activity.

from documentation regarding onstart:

called when activity becoming visible user.

and onresume:

called when activity start interacting user. @ point activity @ top of activity stack, user input going it.


Comments

Popular posts from this blog

c++ - Convert big endian to little endian when reading from a binary file -

C#: Application without a window or taskbar item (background app) that can still use Console.WriteLine() -

unicode - Are email addresses allowed to contain non-alphanumeric characters? -