Android Lollipop: Launcher crashes when adding app widget to Home Screen

╄→гoц情女王★ 提交于 2020-01-02 04:31:09

问题


The Launcher crashes on Android Lollipop when adding a Widget giving the following message (It works fine on previous Android versions):

Edit: This only happens in landscape orientation.

12-16 12:35:10.208: E/AndroidRuntime(960): 
java.lang.RuntimeException: Unable to resume activity {com.android.launcher/com.android.launcher2.Launcher}: java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=5, result=-1, data=Intent { (has extras) }}  to activity {com.android.launcher/com.android.launcher2.Launcher}: java.lang.NullPointerException:      Attempt to read from field 'android.content.pm.ActivityInfo     
android.appwidget.AppWidgetProviderInfo.providerInfo' on a null object reference
12-16 12:35:10.208: E/AndroidRuntime(960):  at 
android.appwidget.AppWidgetHostView.getRemoteContext(AppWidgetHostView.java:465)
12-16 12:35:10.208: E/AndroidRuntime(960):  at   
android.appwidget.AppWidgetHostView.updateAppWidget(AppWidgetHostView.java:376)
12-16 12:35:10.208: E/AndroidRuntime(960):  at com.android.launcher2.LauncherAppWidgetHostView.updateAppWidget(LauncherAppWidgetHostView.java:54)
12-16 12:35:10.208: E/AndroidRuntime(960):  at android.appwidget.AppWidgetHost.createView(AppWidgetHost.java:325)
12-16 12:35:10.208: E/AndroidRuntime(960):  at com.android.launcher2.Launcher.completeTwoStageWidgetDrop(Launcher.java:703)
12-16 12:35:10.208: E/AndroidRuntime(960):  at  com.android.launcher2.Launcher.onActivityResult(Launcher.java:664)

This is the provider info:

<?xml version="1.0" encoding="utf-8"?>
<appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android"
  android:minWidth="201dp"
  android:minHeight="201dp"
  android:updatePeriodMillis="180000"
  android:initialLayout="@layout/appwidget_week"
  android:configure="com.example.myApp.Widgets.Configure.WidgetConfigure_Week"
  android:resizeMode="horizontal|vertical"
  android:previewImage="@drawable/widget_screenshot_week" 
  android:label="@string/widget_week">
</appwidget-provider> 

And the manifest:

    <receiver
        android:name="com.example.myApp.Widgets.Provider.WidgetProvider_Week"
        android:enabled="@bool/is_above_version_3_1"
        android:label="@string/widget_week" >
        <intent-filter>
            <action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
        </intent-filter>

        <meta-data
            android:name="android.appwidget.provider"
            android:resource="@xml/appwidget_week_provider_info" />
    </receiver>

回答1:


I had a similar crash occur on Marshmallow. My crash occurred when the screen orientation was changed while in the Activity used to configure the Home-screen Widget (it did not occur in either orientation if the orientation was not changed).

Just to clarify: the crash did not occur immediately when the screen was rotated. Rather it occurred after the user finished configurating the widget, exited the Activity, and Android was in the process of creating the Home Screen Widget.

This also caused "phantom widgets" (i.e. widgets that do not appear on the screen but exist inside Android) to be created.

I was able to resolve it by forcing the Widget Configuration Activity to stay in portrait-mode when the device was rotated. As described here:

Force "portrait" orientation mode



来源:https://stackoverflow.com/questions/27503926/android-lollipop-launcher-crashes-when-adding-app-widget-to-home-screen

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!