0

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.

SamJ
  • 413
  • 1
  • 4
  • 18
  • No it is already Clickable but how can i do things that i cam only make in activities like displaying a toast message when the widget is clicked.Please support me with any possible way. – SamJ Aug 13 '13 at 18:46
  • 1
    Does [this](http://stackoverflow.com/a/12511980/645270) help? – keyser Aug 13 '13 at 18:48
  • [This link](http://stackoverflow.com/questions/2471875/processing-more-than-one-button-click-at-android-widget) has been helpful i've tried it before but i don't know why it worked this time but now i have another problem .I've putted a toast message before the method responsible for turning the flashlight on/off . the first time i click the widget a toast message pops up the led turns on the second time i click it , it just crashes and doesn't even display the toast message before crashing – SamJ Aug 13 '13 at 20:35
  • When your app crashes, just check the logcat to find out why. It'll give you the cause and a line number. – keyser Aug 13 '13 at 20:43

1 Answers1

0

I've solved the problem.The problem was that the program was turning gthe led on when it already was on.

What the program does?

The first time i click the widget the led is turned on and a boolean is turned false .

Problem

the program is turning the boolean false simple because it's not static

SamJ
  • 413
  • 1
  • 4
  • 18