0

After clicking on the widget, my code launches a new activity. This is how I have done

public class ExampleAppWidgetProvider extends AppWidgetProvider {
 @Override
   public void onUpdate(Context context, AppWidgetManager appWidgetManager,
   int[] appWidgetIds) {
      for(int i=0; i<appWidgetIds.length; i++){
      int currentWidgetId = appWidgetIds[i];
      String url = "http://www.tutorialspoint.com";
      Intent intent = new Intent(Intent.ACTION_VIEW);
      intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
      intent.setData(Uri.parse(url));
      PendingIntent pending = PendingIntent.getActivity(context, 0,
      intent, 0);
      RemoteViews views = new RemoteViews(context.getPackageName(),
      R.layout.widget1);
      views.setOnClickPendingIntent(R.id.button, pending);
      appWidgetManager.updateAppWidget(currentWidgetId,views);
     // Toast.makeText(context, "widget clicked ", Toast.LENGTH_SHORT).show();  
      }
   }    

}

I don't want to launch that activity, rather I just want to simply show a Toast near the widget area.

I can I do this..?

Helpp!!

EDIT

My question does not have the answer in this question android widget on click event

However I tried using this code also

public class ExampleAppWidgetProvider extends AppWidgetProvider {
@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager,
int[] appWidgetIds) {
  Toast.makeText(context, "widget clicked ", Toast.LENGTH_SHORT).show();  
  }
}

But This shows toast only when the widget is placed on the home screen by user, toast is not shown when the user clicks the widget & nothing happens, onUpdate is also not called then !

Community
  • 1
  • 1
Vivek Warde
  • 1,936
  • 8
  • 47
  • 77

1 Answers1

1
public class ExampleAppWidgetProvider extends AppWidgetProvider {
 @Override
   public void onUpdate(Context context, AppWidgetManager appWidgetManager,
   int[] appWidgetIds) {
      Toast.makeText(context, "widget clicked ", Toast.LENGTH_SHORT).show();  
      }
   }
Basquare
  • 11
  • 3
  • I have already tried this before posting this question, By ur answer the toast is displayed only on the widget placement. By using ur code it neither launches any thing(thats fine) but it doesnt display the toast... There must be a another way out there – Vivek Warde May 11 '15 at 10:57