I still haven't been able to do advanced stuff in widgets.Let's say i have a method for doing something like turning the flashlight On.How can i call this method from the widget using anyway possible way like Async , services ... My Code (Widget):
public class QFlashlightWidgetProvider extends AppWidgetProvider {
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
final int N = appWidgetIds.length;
// Perform this loop procedure for each App Widget that belongs to this provider
for (int i=0; i<N; i++) {
int appWidgetId = appWidgetIds[i];
// Create an Intent to launch QFlashlightActivity
Intent intent = new Intent(context, ScreenLight.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.qflashlight_appwidget);
views.setOnClickPendingIntent(R.id.btn1, pendingIntent);
// Tell the AppWidgetManager to perform an update on the current app widget
appWidgetManager.updateAppWidget(appWidgetId, views);
}
}
}
Please support me with any code that can at least call a toast message when the widget is clicked.This simply a widget that will open my activity once clicked.