Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to present a toast when a widget is clicked?

I need to do a simple widget that presents a Toast when clicking on it. My problem is that I cant find how to get or create an "oncreate" action. i see the examples with the pending intent that opens the web browser. But how do i simply create this: Toast.makeText(context, "activated", Toast.LENGTH_LONG).show(); and make it happen every time a user clicks on the widget? just to be clear, I mean a widget on the launcher of the phone. not a regular "button" widget etc...

public class Widget extends AppWidgetProvider {
NotificationManager mNotificationManager;
Notification notification;

@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
    super.onUpdate(context, appWidgetManager, appWidgetIds);



    appWidgetManager.updateAppWidget(appWidgetIds, view);
}

}

Thanks!

like image 791
roiberg Avatar asked Oct 20 '25 18:10

roiberg


1 Answers

Just call Toast.makeText(context, "activated", Toast.LENGTH_LONG).show(); in widget's onClick() method of View.OnClickListener

Update:

If you use AppWidgetProvider so check this and this one posts

like image 153
teoREtik Avatar answered Oct 23 '25 08:10

teoREtik



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!