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!
I think you are missing to show the created
Toast
. For example:Moreover, override the
onClick
method of your customView
class and pop the toast there.folks my VS environment is VS 2017 with Xamarin .
and use this function to show message at device screen like below:
this may helps , here need to pass context and get Onclick Event with your widget
Toast.makeText(context, "activated", Toast.LENGTH_LONG).show();
Just call
Toast.makeText(context, "activated", Toast.LENGTH_LONG).show();
in widget'sonClick()
method ofView.OnClickListener
Update:
If you use
AppWidgetProvider
so check this and this one postsTry this:
This is my BroadcastReciever Class:
Here, I called my activity class.. and I did my widget design in My activity class..