[Java for Android App Development] thecosmicfrog:
I have a really strange problem with my app widget. There's no issues with dragging it to the homescreen, configuration or even functionality. Everything works as expected.

But, after an arbitrary length of time, my launcher starts to crash. I've gone days at a time without experiencing this, and sometimes just minutes. In fact, there's seemingly no way to recover it without opening the Recent Apps screen, finding the Play Store or Settings and just uninstalling the app.

My app's package name is org.thecosmicfrog.luasataglance. Almost all of what the widget does is handled by a Service, which is created when a user taps part of the widget.

The widget is located at: org.thecosmicfrog.luasataglance.widget.StopForecastWidget

The Service is located at: org.thecosmicfrog.luasataglance.service.WidgetListenerService

I've attached the output of LogCat just after the crash below. You can see where the Google Now launcher starts to crash (com.google.android.googlequicksearchbox), but this affects other launchers too:

10-04 03:28:07.769 I/GEL (1330): handleIntent(Intent { act=android.intent.action.MAIN cat=[android.intent.category.HOME] flg=0x10600000 cmp=com.google.android.googlequicksearchbox/com.google.android.launcher.GEL })
10-04 03:28:07.829 D/AudioManager(1244): AudioManager dispatching onAudioFocusChange(-3) for android.media.AudioManager@1fa1d3d8kom@37833331
10-04 03:28:07.867 D/Launcher(1330): bindAppWidget: AppWidget(id=153)
10-04 03:28:07.871 D/Launcher(1330): bindAppWidget: id=153 belongs to component ComponentInfo{org.thecosmicfrog.luasataglance/org.thecosmicfrog.luasataglance.widget.StopForecastWidget}
10-04 03:28:07.931 I/art (2036): Explicit concurrent mark sweep GC freed 22778(1189KB) AllocSpace objects, 0(0B) LOS objects, 38% free, 25MB/41MB, paused 2.368ms total 104.811ms
10-04 03:28:07.971 I/WindowManager(789): Screen frozen for +445ms due to Window{1d871ef2 u0 StatusBar}
10-04 03:28:08.308 E/JavaBinder(1330): !!! FAILED BINDER TRANSACTION !!!
10-04 03:28:08.315 D/AndroidRuntime(1330): Shutting down VM
10-04 03:28:08.422 I/MediaFocusControl(789): AudioFocus abandonAudioFocus() from android.media.AudioManager@330313aa
10-04 03:28:08.424 I/ActivityManager(789): Start proc 23910:com.google.android.googlequicksearchbox:crash_report/u0a24 for service com.google.android.googlequicksearchbox/com.google.android.apps.gsa.silentfeedback.SilentFeedbackService
10-04 03:28:08.424 D/AudioManager(1244): AudioManager dispatching onAudioFocusChange(1) for android.media.AudioManager@1fa1d3d8kom@37833331
--------- beginning of crash
10-04 03:28:08.425 E/AndroidRuntime(1330): FATAL EXCEPTION: main
10-04 03:28:08.425 E/AndroidRuntime(1330): Process: com.google.android.googlequicksearchbox, PID: 1330
10-04 03:28:08.425 E/AndroidRuntime(1330): java.lang.RuntimeException: Unable to resume activity {com.google.android.googlequicksearchbox/com.google.android.launcher.GEL}: java.lang.RuntimeException: system server dead?
10-04 03:28:08.425 E/AndroidRuntime(1330): at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2986)
10-04 03:28:08.425 E/AndroidRuntime(1330): at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:3017)
10-04 03:28:08.425 E/AndroidRuntime(1330): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1347)
10-04 03:28:08.425 E/AndroidRuntime(1330): at android.os.Handler.dispatchMessage(Handler.java:102)
10-04 03:28:08.425 E/AndroidRuntime(1330): at android.os.Looper.loop(Looper.java:135)
10-04 03:28:08.425 E/AndroidRuntime(1330): at android.app.ActivityThread.main(ActivityThread.java:5254)
10-04 03:28:08.425 E/AndroidRuntime(1330): at java.lang.reflect.Method.invoke(Native Method)
10-04 03:28:08.425 E/AndroidRuntime(1330): at java.lang.reflect.Method.invoke(Method.java:372)
10-04 03:28:08.425 E/AndroidRuntime(1330): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
10-04 03:28:08.425 E/AndroidRuntime(1330): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
10-04 03:28:08.425 E/AndroidRuntime(1330): at de.robv.android.xposed.XposedBridge.main(XposedBridge.java:115)
10-04 03:28:08.425 E/AndroidRuntime(1330): Caused by: java.lang.RuntimeException: system server dead?
10-04 03:28:08.425 E/AndroidRuntime(1330): at android.appwidget.AppWidgetHost.createView(AppWidgetHost.java:323)
10-04 03:28:08.425 E/AndroidRuntime(1330): at com.android.launcher3.LauncherAppWidgetHost.createView(LauncherAppWidgetHost.java:116)
10-04 03:28:08.425 E/AndroidRuntime(1330): at com.android.launcher3.Launcher.bindAppWidget(Launcher.java:3950)
10-04 03:28:08.425 E/AndroidRuntime(1330): at com.android.launcher3.Workspace.reinflateWidgetsIfNecessary(Workspace.java:1124)
10-04 03:28:08.425 E/AndroidRuntime(1330): at com.android.launcher3.Launcher.onResume(Launcher.java:1044)
10-04 03:28:08.425 E/AndroidRuntime(1330): at de.robv.android.xposed.XposedBridge.invokeOriginalMethodNative(Native Method)
10-04 03:28:08.425 E/AndroidRuntime(1330): at de.robv.android.xposed.XposedBridge.handleHookedMethod(XposedBridge.java:650)
10-04 03:28:08.425 E/AndroidRuntime(1330): at com.android.launcher3.Launcher.onResume(<Xposed>)
10-04 03:28:08.425 E/AndroidRuntime(1330): at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1257)
10-04 03:28:08.425 E/AndroidRuntime(1330): at android.app.Activity.performResume(Activity.java:6076)
10-04 03:28:08.425 E/AndroidRuntime(1330): at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2975)
10-04 03:28:08.425 E/AndroidRuntime(1330): ... 10 more
10-04 03:28:08.425 E/AndroidRuntime(1330): Caused by: android.os.TransactionTooLargeException
10-04 03:28:08.425 E/AndroidRuntime(1330): at android.os.BinderProxy.transactNative(Native Method)
10-04 03:28:08.425 E/AndroidRuntime(1330): at android.os.BinderProxy.transact(Binder.java:496)
10-04 03:28:08.425 E/AndroidRuntime(1330): at com.android.internal.appwidget.IAppWidgetService$Stub$Proxy.getAppWidgetViews(IAppWidgetService.java:538)
10-04 03:28:08.425 E/AndroidRuntime(1330): at android.appwidget.AppWidgetHost.createView(AppWidgetHost.java:321)
10-04 03:28:08.425 E/AndroidRuntime(1330): ... 20 more
10-04 03:28:08.470 W/ActivityManager(789): Force finishing activity 1 com.google.android.googlequicksearchbox/com.google.android.launcher.GEL
10-04 03:28:08.517 D/OpenGLRenderer(789): Use EGL_SWAP_BEHAVIOR_PRESERVED: true
10-04 03:28:08.518 D/Atlas (789): Validating map...
10-04 03:28:08.519 I/Xposed (23910): GB:ModLauncher: Couldn't find dynamic grid. Incompatible Google Search?
10-04 03:28:08.538 W/XPrivacy(23910): Hooking package=com.google.android.googlequicksearchbox
10-04 03:28:08.575 I/OpenGLRenderer(789): Initialized EGL, version 1.4
10-04 03:28:08.603 D/OpenGLRenderer(789): Enabling debug mode 0
10-04 03:28:08.847 I/ActivityManager(789): Killing 19499:com.emmaguy.todayilearned/u0a92 (adj 15): empty #17
10-04 03:28:08.972 W/ActivityManager(789): Activity pause timeout for ActivityRecord{22486d04 u0 com.google.android.googlequicksearchbox/com.google.android.launcher.GEL t5986 f}

Later on in the log, there is more output related to app widgets which may be useful too:

10-04 03:28:15.661 I/Process (1330): Sending signal. PID: 1330 SIG: 9
10-04 03:28:15.691 I/WindowState(789): WIN DEATH: Window{389c7f61 u0 com.google.android.googlequicksearchbox/com.google.android.launcher.GEL}
10-04 03:28:15.737 I/ActivityManager(789): Process com.google.android.googlequicksearchbox (pid 1330) has died
10-04 03:28:15.739 W/ActivityManager(789): Scheduling restart of crashed service com.google.android.googlequicksearchbox/com.google.android.apps.gsa.reflection.ReflectionService in 1000ms
10-04 03:28:15.745 W/IInputConnectionWrapper(1244): showStatusIcon on inactive InputConnection
10-04 03:28:16.176 W/ResourceType(952): No package identifier when getting value for resource number 0x00000000
10-04 03:28:16.350 W/ResourceType(952): No package identifier when getting value for resource number 0x00000000
10-04 03:28:16.350 W/PackageManager(952): Failure retrieving resources for org.thecosmicfrog.luasataglance: Resource ID #0x0
10-04 03:28:16.861 D/audio_hw_primary(188): out_set_parameters: enter: usecase(1: low-latency-playback) kvpairs: routing=2
10-04 03:28:17.657 D/AndroidRuntime(24056): >>>>>> START com.android.internal.os.RuntimeInit uid 0 <<<<<<
10-04 03:28:17.670 D/AndroidRuntime(24056): CheckJNI is OFF
10-04 03:28:17.954 I/ActivityManager(789): Start proc 24076:eu.chainfire.supersu/u0a84 for broadcast eu.chainfire.supersu/.NativeAccessReceiver
10-04 03:28:17.984 W/ResourceType(952): No package identifier when getting value for resource number 0x00000000
10-04 03:28:17.984 W/PackageManager(952): Failure retrieving resources for com.google.android.youtube: Resource ID #0x0
10-04 03:28:18.066 W/XPrivacy(24076): Hooking package=eu.chainfire.supersu
10-04 03:28:18.570 D/AndroidRuntime(24137): >>>>>> START com.android.internal.os.RuntimeInit uid 0 <<<<<<
10-04 03:28:18.574 D/AndroidRuntime(24137): CheckJNI is OFF
10-04 03:28:18.565 W/app_process32_x(24137): type=1400 audit(0.0:95): avc: denied { write } for name="system@framework@boot.art" dev="mmcblk0p28" ino=491525 scontext=u:r:shell:s0 tcontext=u:object_r:dalvikcache_data_file:s0 tclass=file
10-04 03:28:18.709 D/AndroidRuntime(24137): Calling main entry com.android.commands.am.Am
10-04 03:28:18.746 D/AndroidRuntime(24137): Shutting down VM
10-04 03:28:18.855 W/app_process32_x(24167): type=1400 audit(0.0:96): avc: denied { write } for name="system@framework@boot.art" dev="mmcblk0p28" ino=491525 scontext=u:r:shell:s0 tcontext=u:object_r:dalvikcache_data_file:s0 tclass=file
10-04 03:28:18.859 D/AndroidRuntime(24167): >>>>>> START com.android.internal.os.RuntimeInit uid 0 <<<<<<
10-04 03:28:18.862 D/AndroidRuntime(24167): CheckJNI is OFF
10-04 03:28:18.985 D/AndroidRuntime(24167): Calling main entry com.android.commands.am.Am
10-04 03:28:19.013 D/AndroidRuntime(24167): Shutting down VM
10-04 03:28:19.394 E/AppWidgetServiceImpl(789): Widget host dead: HostId{user:0, app:10024, hostId:1024, pkg:com.google.android.googlequicksearchbox}
10-04 03:28:19.394 E/AppWidgetServiceImpl(789): android.os.DeadObjectException
10-04 03:28:19.394 E/AppWidgetServiceImpl(789): at android.os.BinderProxy.transactNative(Native Method)
10-04 03:28:19.394 E/AppWidgetServiceImpl(789): at android.os.BinderProxy.transact(Binder.java:496)
10-04 03:28:19.394 E/AppWidgetServiceImpl(789): at com.android.internal.appwidget.IAppWidgetHost$Stub$Proxy.updateAppWidget(IAppWidgetHost.java:123)
10-04 03:28:19.394 E/AppWidgetServiceImpl(789): at com.android.server.appwidget.AppWidgetServiceImpl.handleNotifyUpdateAppWidget(AppWidgetServiceImpl.java:1638)
10-04 03:28:19.394 E/AppWidgetServiceImpl(789): at com.android.server.appwidget.AppWidgetServiceImpl.access$1200(AppWidgetServiceImpl.java:107)
10-04 03:28:19.394 E/AppWidgetServiceImpl(789): at com.android.server.appwidget.AppWidgetServiceImpl$CallbackHandler.handleMessage(AppWidgetServiceImpl.java:2962)
10-04 03:28:19.394 E/AppWidgetServiceImpl(789): at android.os.Handler.dispatchMessage(Handler.java:102)
10-04 03:28:19.394 E/AppWidgetServiceImpl(789): at android.os.Looper.loop(Looper.java:135)
10-04 03:28:19.394 E/AppWidgetServiceImpl(789): at com.android.server.SystemServer.run(SystemServer.java:269)
10-04 03:28:19.394 E/AppWidgetServiceImpl(789): at com.android.server.SystemServer.main(SystemServer.java:170)
10-04 03:28:19.394 E/AppWidgetServiceImpl(789): at java.lang.reflect.Method.invoke(Native Method)
10-04 03:28:19.394 E/AppWidgetServiceImpl(789): at java.lang.reflect.Method.invoke(Method.java:372)
10-04 03:28:19.394 E/AppWidgetServiceImpl(789): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
10-04 03:28:19.394 E/AppWidgetServiceImpl(789): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
10-04 03:28:19.394 E/AppWidgetServiceImpl(789): at de.robv.android.xposed.XposedBridge.main(XposedBridge.java:115)

I'm finding this incredibly difficult to debug, so any help offered would be greatly appreciated. If you require any more information, I'll be happy to provide it.