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 !