Android Lollipop:将应用小部件添加到主屏幕时,启动器崩溃 [英] Android Lollipop: Launcher crashes when adding app widget to Home Screen

查看:202
本文介绍了Android Lollipop:将应用小部件添加到主屏幕时,启动器崩溃的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

添加小部件并显示以下消息时,启动器在Android Lollipop上崩溃 (在以前的Android版本上可以正常使用):

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

这仅在横向方向上发生.

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)

这是提供商信息:

<?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> 

清单:

    <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>

推荐答案

我在棉花糖上也发生了类似的崩溃.在用于配置主屏幕小部件的活动"中更改了屏幕方向时发生了我的崩溃(如果未更改方向,则不会在任何一个方向上发生).

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).

只需澄清一下:旋转屏幕时并没有立即发生崩溃.而是在用户完成对小部件的配置,退出活动以及Android正在创建主屏幕小部件的过程中发生的.

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.

这还会导致创建虚拟小部件"(即,未显示在屏幕上但存在于Android中的小部件).

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:

强制使用纵向"方向模式

这篇关于Android Lollipop:将应用小部件添加到主屏幕时,启动器崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆