App widget crash during second configuration launch

974 views Asked by At

I am developing an app widget which launches a configuration activity when the widget is moved to the screen. The first time I place the widget on the screen, the configuration launches and runs successfully. After I removed the widget, then placed it on the screen again, the activity crashes, with logcat showing the following:

E/AndroidRuntime(15830): FATAL EXCEPTION: main
E/AndroidRuntime(15830): Process: com.lge.launcher2, PID: 15830
E/AndroidRuntime(15830): java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=5, result=-1, data=Intent { (has extras) }} to activity {com.lge.launcher2/com.lge.launcher2.Launcher}: java.lang.NullPointerException: Attempt to read from field 'android.content.ComponentName android.appwidget.AppWidgetProviderInfo.provider' on a null object reference
E/AndroidRuntime(15830):    at android.app.ActivityThread.deliverResults(ActivityThread.java:3554)
E/AndroidRuntime(15830):    at android.app.ActivityThread.handleSendResult(ActivityThread.java:3597)
E/AndroidRuntime(15830):    at android.app.ActivityThread.access$1300(ActivityThread.java:148)
E/AndroidRuntime(15830):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1332)
E/AndroidRuntime(15830):    at android.os.Handler.dispatchMessage(Handler.java:102)
E/AndroidRuntime(15830):    at android.os.Looper.loop(Looper.java:135)
E/AndroidRuntime(15830):    at android.app.ActivityThread.main(ActivityThread.java:5272)
E/AndroidRuntime(15830):    at java.lang.reflect.Method.invoke(Native Method)
E/AndroidRuntime(15830):    at java.lang.reflect.Method.invoke(Method.java:372)
E/AndroidRuntime(15830):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:909)
E/AndroidRuntime(15830):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:704)
E/AndroidRuntime(15830): Caused by: java.lang.NullPointerException: Attempt to read from field 'android.content.ComponentName android.appwidget.AppWidgetProviderInfo.provider' on a null object reference
E/AndroidRuntime(15830):    at com.lge.launcher2.views.LauncherAppWidgetHostView.<init>(LauncherAppWidgetHostView.java:71)
E/AndroidRuntime(15830):    at com.lge.launcher2.application.LauncherAppWidgetHost.onCreateView(LauncherAppWidgetHost.java:56)
E/AndroidRuntime(15830):    at android.appwidget.AppWidgetHost.createView(AppWidgetHost.java:313)
E/AndroidRuntime(15830):    at com.lge.launcher2.application.WidgetManager.createView(WidgetManager.java:105)
E/AndroidRuntime(15830):    at com.lge.launcher2.Launcher.completeAddAppWidget(Launcher.java:1670)
E/AndroidRuntime(15830):    at com.lge.launcher2.Launcher.completeAdd(Launcher.java:649)
E/AndroidRuntime(15830):    at com.lge.launcher2.Launcher.onActivityResult(Launcher.java:685)
E/AndroidRuntime(15830):    at android.app.Activity.dispatchActivityResult(Activity.java:6179)
E/AndroidRuntime(15830):    at android.app.ActivityThread.deliverResults(ActivityThread.java:3550)
E/AndroidRuntime(15830):    ... 10 more
W/ActivityManager( 1022):   Force finishing activity com.lge.launcher2/.Launcher
W/ResourcesManager(14274): Asset path '/system/framework/com.google.android.maps.jar' does not exist or contains no resources.
W/ResourcesManager(14274): Asset path '/system/framework/com.lge.mdm.jar' does not exist or contains no resources.
W/ResourcesManager(14274): Asset path '/system/framework/com.lge.telephony.sms.jar' does not exist or contains no resources.
W/ResourcesManager(14274): Asset path '/system/framework/lghiddenlibs.jar' does not exist or contains no resources.
W/ResourcesManager(14274): Asset path '/system/framework/qcrilhook.jar' does not exist or contains no resources.
W/PhoneWindowManagerEx( 1022): Call!!!getLGSystemUiVisibility. =0x0
D/StatusBarManagerServiceEx( 1022): setLGSystemUiVisibility(0x0)
D/StatusBarManagerServiceEx( 1022): manageNaviBtnDisableList userId=0 what=0x0 pkg=WindowManager.LayoutParams

I toggled the "Don't keep activities" configuration as suggested in this question, but that didn't change anything. My test system is an LG3 device running Lollipop. What causes the crash?

Additional points

  1. If I wait at the first input screen for a while (TBD how long exactly) the same crash occurs.
  2. I set the result in onCreate as follows:

    Intent resultValue = new Intent(); resultValue.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId); setResult(RESULT_CANCELED, resultValue);

and when the user completes the configuration process, as follows:

 Intent resultValue = new Intent();
 resultValue.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
 setResult(RESULT_OK, resultValue);
 finish();
  1. My problem might be related to this question, which has not been answered.
2

There are 2 answers

0
Aharon Manne On

When the configuration activity is regenerated, either on rotation of the screen or placement of a new widget, I wanted to immediately exit the configuration activity, so I called finish() in the middle of onCreate(). This did bad things, and caused the exception in questions.

0
user1050133 On

AppWidgetId is valid also does not only mean that it has been passed to the activity but also that it has been registered within Android's AppWidgetManager. This happens by default before calling the configuration activity.

However, in my case, I deleted appWidgetIds manually from Android's AppWidgetManager whenever onUpdate was called an the preference was not known to my application. Lesson learned - don't change Android's appwidget state.