Note that there are some explanatory texts on larger screens.

plurals
  1. POhow to check if widget is in background in android
    primarykey
    data
    text
    <p>I am developing torch. I have developed widget with a single button. If you click on that button it turns on torch and if you click again it turns off torch. BUT when torch is ON and user pressed Power button to turn off screen it also turns off the torch. So I want to check if device has gone to sleep mode while torch was on, can someone help me ?</p> <p>here is my code to turn torch on and off in widget</p> <pre><code>public void onReceive(Context context, Intent intent) { Log.d("torchWidget", "onReceive"); final String action = intent.getAction(); if(AppWidgetManager.ACTION_APPWIDGET_DELETED.equals(action)) { final int appWidgetId = intent.getExtras().getInt( AppWidgetManager.EXTRA_APPWIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID); if(appWidgetId != AppWidgetManager.INVALID_APPWIDGET_ID) { this.onDeleted(context, new int[] { appWidgetId }); } } else{ if(intent.getAction().equals(ACTION_WIDGET_RECEIVER)) { String msg = "null"; try{ msg = intent.getStringExtra("msg"); msg = "Flash Turned On"; } catch(NullPointerException e) { Log.e("Error", "msg = null"); } if(Constants.isFlashOnWidget){ Constants.isFlashOnWidget = false; Toast.makeText(context, "Flash turned OFF", Toast.LENGTH_SHORT).show(); Intent serviceIntent = new Intent(context.getApplicationContext(), BackgroundService.class); context.stopService(serviceIntent); } else { Constants.isFlashOnWidget = true; Intent serviceIntent = new Intent(context.getApplicationContext(), BackgroundService.class); context.startService(serviceIntent); } } super.onReceive(context, intent); } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload