Note that there are some explanatory texts on larger screens.

plurals
  1. POMy android widget crashes launcher. How do I debug that?
    text
    copied!<p>I have developed a simple widget which has two buttons switching my dual-sim phone sim cards on and off. I wire buttons click within onUpdate method of my AppWidgetProvider implementation. Unfortinately after few successfull clicks, launcher reloads(I observe short blink on my device screen) and my widget no longer does anything on button clicks.</p> <p>I tried to look at my LogCat but didn't find anything interesting for the launcher app there.</p> <p>Now the question is how do I debug such situation?</p> <p>edit: Here is some code of my AppWidgetProvider. I understand that the code is naive and needs some refactoring, but I still need to debug that launcher crash somehow:</p> <pre><code> @Override public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) { RemoteViews remoteViews; ComponentName widget; remoteViews = new RemoteViews(context.getPackageName(), R.layout.widget_layout); widget = new ComponentName(context, ExampleAppWidgetProvider.class); int currentState = Settings.System.getInt(context.getContentResolver(), "dual_sim_mode_setting", -1); String sim1Text = currentState == 1 || currentState == 3 ? "on" : "off"; String sim2Text = currentState == 2 || currentState == 3 ? "on" : "off"; remoteViews.setTextViewText(R.id.first_button, sim1Text); remoteViews.setTextViewText(R.id.second_button, sim2Text); remoteViews.setOnClickPendingIntent(R.id.first_button, getPendingSelfIntent(context, SIM1_CLICKED)); remoteViews.setOnClickPendingIntent(R.id.second_button, getPendingSelfIntent(context, SIM2_CLICKED)); appWidgetManager.updateAppWidget(widget, remoteViews); } @Override public void onReceive(Context context, Intent intent) { // TODO Auto-generated method stub if ("android.appwidget.action.APPWIDGET_UPDATE".equals(intent.getAction())) { super.onReceive(context, intent); return; } if (SIM1_CLICKED.equals(intent.getAction())) { switchSim(1, context); return; } else if (SIM2_CLICKED.equals(intent.getAction())){ switchSim(2, context); } else if ("android.intent.action.DUAL_SIM_MODE".equals(intent.getAction())){ AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context); RemoteViews remoteViews; ComponentName watchWidget; remoteViews = new RemoteViews(context.getPackageName(), R.layout.widget_layout); watchWidget = new ComponentName(context, ExampleAppWidgetProvider.class); int mode = intent.getIntExtra("mode", -1); switch (mode) { case 0: remoteViews.setTextViewText(R.id.first_button, "off"); remoteViews.setTextViewText(R.id.second_button, "off"); break; case 1: remoteViews.setTextViewText(R.id.first_button, "on"); remoteViews.setTextViewText(R.id.second_button, "off"); break; case 2: remoteViews.setTextViewText(R.id.first_button, "off"); remoteViews.setTextViewText(R.id.second_button, "on"); break; case 3: remoteViews.setTextViewText(R.id.first_button, "on"); remoteViews.setTextViewText(R.id.second_button, "on"); break; } appWidgetManager.updateAppWidget(watchWidget, remoteViews); } } </code></pre>
 

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