android widget unresponsive

Posted by John on Stack Overflow See other posts from Stack Overflow or by John
Published on 2010-06-14T00:45:24Z Indexed on 2010/06/14 0:52 UTC
Read the original article Hit count: 219

Filed under:
|
|

I have a widget that you press and it then it will update the text on the widget. I have set an on click listener to launch another activity to perform the text update, But for some reason it only works temporarily and then it will become unresponsive and not do anything when pressed. Does anyone know why it might be doing that? i have posted my widget code below in case it is helpful.

@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager,int[] appWidgetIds) {
    thisWidget = new ComponentName(context, MemWidget.class);
    Intent intent = new Intent(context, updatewidget.class);
    PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, 0);

    // Get the layout for the App Widget and attach an on-click listener to the button
    RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.widget);
    views.setOnClickPendingIntent(R.id.ImageButton01, pendingIntent);

    // Tell the AppWidgetManager to perform an update on the current App Widget
    appWidgetManager.updateAppWidget(thisWidget, views);

}

@Override
public void onReceive(Context context, Intent intent) 
{
    appWidgetManager = AppWidgetManager.getInstance(context);
    remoteViews = new RemoteViews(context.getPackageName(), R.layout.widget);
    thisWidget = new ComponentName(context, MemWidget.class);

    // v1.5 fix that doesn't call onDelete Action
    final String action = intent.getAction();
    if (AppWidgetManager.ACTION_APPWIDGET_DELETED.equals(action)) {
        final int appWidgetId = intent.getExtras().getInt(
            AppWidgetManager.EXTRA_APPWIDGET_ID,
            AppWidgetManager.INVALID_APPWIDGET_ID);
            if (appWidgetId != AppWidgetManager.INVALID_APPWIDGET_ID) {
                this.onDeleted(context, new int[] { appWidgetId });
            }
        } 
    else 
    {   
        super.onReceive(context, intent);
    }
}

© Stack Overflow or respective owner

Related posts about android

Related posts about widget