Note that there are some explanatory texts on larger screens.

plurals
  1. POlogging to a database when user clicks on a widget
    primarykey
    data
    text
    <p>I have a widget that displays an analog clock. What I would like is for the the widget to write to a database the time when a user clicks on the widget. I've already got the databaseHelper class and have an Activity that displays a screen showing the current date and time and writes the time to a database.</p> <p>I followed the tutorial here: <a href="http://nexsoftware.net/wp/2009/07/29/tutorial-creating-a-custom-analogclock-widget/" rel="nofollow noreferrer">Analog Clock Tutorial</a> and ended up with this:</p> <pre><code>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); } } </code></pre> <p>The AskTheTime class extends activity and logs to the database in onCreate(). But this means that it displays only the time when the widget was started - not when it was clicked. (I guess this is because I'm starting a pendingIntent) I'm not sure If I should put the database write in another method or if I should be using Intents to do this sort of thing from widgets. Any pointers would be great! I've look at several tutorials for intents but none of them seem very clear to me.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload