Android 安卓小部件-怪异“;“加载小部件”;错误

Android 安卓小部件-怪异“;“加载小部件”;错误,android,widget,Android,Widget,我的可配置时钟小部件有一个奇怪的问题,我无法调试:( 这是我的第一个小部件,很简单;),它是一个后台可配置的时钟小部件。 当用户选择小部件时,将启动配置活动。在此活动中,用户可以选择时钟的小部件背景。当用户完成配置时,一个带有用户背景的“标准时钟小部件”出现在启动器屏幕上,仅此而已。 我对它进行了彻底的测试,它似乎一直工作到。。。 我遇到的问题是,当我打开并解锁屏幕时,我的小部件“消失”了,我有一个灰色框,上面有可怕的“问题加载小部件”错误:( 所以,我有一个错误,我不能得到一个可复制的场景,可

我的可配置时钟小部件有一个奇怪的问题,我无法调试:( 这是我的第一个小部件,很简单;),它是一个后台可配置的时钟小部件。 当用户选择小部件时,将启动配置活动。在此活动中,用户可以选择时钟的小部件背景。当用户完成配置时,一个带有用户背景的“标准时钟小部件”出现在启动器屏幕上,仅此而已。 我对它进行了彻底的测试,它似乎一直工作到。。。 我遇到的问题是,当我打开并解锁屏幕时,我的小部件“消失”了,我有一个灰色框,上面有可怕的“问题加载小部件”错误:( 所以,我有一个错误,我不能得到一个可复制的场景,可能是一个生命周期小部件方法错误相关? 当错误出现时,我在日志中看不到任何问题,所以我完全迷路了

这是这个小部件的简单代码:(GB2.3.3)。我去掉了不重要的部分

1.-小部件提供程序xml

<appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android"
android:minHeight="190dp"
android:minWidth="170dp"
android:configure="......"
android:initialLayout="@drawable/......"
android:updatePeriodMillis="30000" >
</appwidget-provider>
5.配置活动(Java)

  • 它可能与updatePeriodMillis有关请查看updatePeriodMillis的
updatePeriodMillis属性定义应用程序小部件框架通过调用onUpdate()从AppWidgetProvider请求更新的频率回调方法。使用此值不能保证实际更新会准时进行,我们建议尽可能不频繁地更新,可能不超过每小时一次,以节省电池电量。您还可以允许用户在配置中调整频率。有些人可能希望股票行情器每15分钟更新一次,或者一天四次

如果不是这样,我建议查看以下参考资料

  • 具有配置活动的Android应用程序小部件
  • 创建一个类似的应用程序

你调试过这个应用程序吗?你尝试过哪些方法来找出发生了什么?你从这些方法中得到了什么结果?我们不能在不知道你已经尝试过什么的情况下提出建议,否则我们只会重复同样的理由。我不知道如何将调试器与小部件一起使用。我在我的手机和it中测试了它´´s继续查找,直到某些生命周期事件使其显示“问题小部件加载文本”错误。该错误发生在移动设备(和小部件)运行数小时后,然后打开屏幕。
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="........"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk
    android:minSdkVersion="10"
    android:targetSdkVersion="10" />

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >

    <activity
        android:name="........"
        android:label="@string/app_name"
        android:screenOrientation="portrait" >
        <intent-filter>
            <action android:name="android.appwidget.action.APPWIDGET_CONFIGURE" />
        </intent-filter>
    </activity>

    <receiver android:name="........." >
        <intent-filter>
            <action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
        </intent-filter>

        <meta-data
            android:name="android.appwidget.provider"
            android:resource="@xml/........" />
    </receiver>
</application>
</manifest>
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/LinearLayout01"
android:layout_width="160dp"
android:layout_height="200dp"
android:orientation="vertical" >

<ImageView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:adjustViewBounds="true"
    android:scaleType="fitXY"
    android:src="@drawable/...." />

<AnalogClock
    android:layout_width="wrap_content"
    android:layout_height="138dp"
    android:layout_gravity="bottom"
    android:dial="@drawable/...."
    android:hand_hour="@drawable/...."
    android:hand_minute="@drawable/...." />
</FrameLayout>
public class ClockProvider extends AppWidgetProvider {
public static int anoEscudo; 

@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
    super.onUpdate(context, appWidgetManager, appWidgetIds);

    RemoteViews remoteView = null;
    for (int appWidgetId : appWidgetIds) {
        // Actualizamos la variable para luego poder modificar el fondo
        switch (anoEscudo) {
        case (...):
            remoteView = new RemoteViews(context.getPackageName(), R.layout....);
            break;
        ...
        }

        appWidgetManager.updateAppWidget(appWidgetId, remoteView);
    }
}
}
package ...;

public class ConfigurationActivity extends Activity {
private int appWidgetId;

ImageView escudo;
TextView descripcion;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);     

    // get the appWidgetId of the appWidget being configured
    Intent launchIntent = getIntent();
    Bundle extras = launchIntent.getExtras();
    appWidgetId = extras.getInt(AppWidgetManager.EXTRA_APPWIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID);

    // set the result for cancel first
    // if the user cancels, then the appWidget
    // should not appear
    Intent cancelResultValue = new Intent();
    cancelResultValue.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
    setResult(RESULT_CANCELED, cancelResultValue);

    // show the user interface of configuration
    setContentView(R.layout.activity_configuration);

    // Setting configuration Activity graphical elements
    // ..
}

//Changing the Widget configuration
private void ... (View view) {      
    switch (escudoSeleccionado) {
    case 1:
        ClockProvider.anoEscudo = ...;
        break;
    ...
    }
}

// Finish the configuration Activity
public void ... (View view) {
    Intent resultValue = new Intent();
    resultValue.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
    setResult(RESULT_OK, resultValue);

    new ClockProvider().onUpdate(this, AppWidgetManager.getInstance(this), new int[] { appWidgetId });

    finish();
}   
}