Android 安卓小部件-怪异“;“加载小部件”;错误
我的可配置时钟小部件有一个奇怪的问题,我无法调试:( 这是我的第一个小部件,很简单;),它是一个后台可配置的时钟小部件。 当用户选择小部件时,将启动配置活动。在此活动中,用户可以选择时钟的小部件背景。当用户完成配置时,一个带有用户背景的“标准时钟小部件”出现在启动器屏幕上,仅此而已。 我对它进行了彻底的测试,它似乎一直工作到。。。 我遇到的问题是,当我打开并解锁屏幕时,我的小部件“消失”了,我有一个灰色框,上面有可怕的“问题加载小部件”错误:( 所以,我有一个错误,我不能得到一个可复制的场景,可能是一个生命周期小部件方法错误相关? 当错误出现时,我在日志中看不到任何问题,所以我完全迷路了 这是这个小部件的简单代码:(GB2.3.3)。我去掉了不重要的部分 1.-小部件提供程序xmlAndroid 安卓小部件-怪异“;“加载小部件”;错误,android,widget,Android,Widget,我的可配置时钟小部件有一个奇怪的问题,我无法调试:( 这是我的第一个小部件,很简单;),它是一个后台可配置的时钟小部件。 当用户选择小部件时,将启动配置活动。在此活动中,用户可以选择时钟的小部件背景。当用户完成配置时,一个带有用户背景的“标准时钟小部件”出现在启动器屏幕上,仅此而已。 我对它进行了彻底的测试,它似乎一直工作到。。。 我遇到的问题是,当我打开并解锁屏幕时,我的小部件“消失”了,我有一个灰色框,上面有可怕的“问题加载小部件”错误:( 所以,我有一个错误,我不能得到一个可复制的场景,可
<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的
- 具有配置活动的Android应用程序小部件
- 创建一个类似的应用程序
<?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();
}
}