1

我创建了一个显示数字时钟的简单 appwidget,并为该时钟设置了 PendingIntent。(即)当用户点击 textview 时,拨号盘被打开。它完美地工作。但是,当我打开一些应用程序(例如 Car Home)然后从 Car Home 退出时,我的主屏幕只会闪一下。我的小部件现在进入无响应状态。我不知道我错了。过去 2 天我在谷歌上搜索这个。任何人请帮忙。

爪哇代码:

 @Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
    super.onUpdate(context, appWidgetManager, appWidgetIds);
    context.startService(new Intent(UpdateService.ACTION_UPDATE));
    RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.main);
    Intent dial = new Intent();
    dial.setAction("android.intent.action.DIAL");
    PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, dial, 0);
    remoteViews.setOnClickPendingIntent(R.id.Time, pendingIntent);
    for (int i = 0; i < appWidgetIds.length; i++) {
        appWidgetManager.updateAppWidget(appWidgetIds[i], remoteViews); 
    }
}

应用小部件提供者:

<?xml version="1.0" encoding="utf-8"?>

<appwidget-provider
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:minWidth="150dip" 
    android:minHeight="72dip"
    android:initialLayout="@layout/main" />

主要的.xml

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:background="#00000000"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" >

    <RelativeLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerVertical="true" >
            <TextView
                android:id="@+id/Time"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:singleLine="true"
                android:ellipsize="none"
                android:textSize="56sp"
                android:textAppearance="?android:attr/textAppearanceMedium"
                android:shadowColor="#C0000000"
                android:shadowDx="0"
                android:shadowDy="0"
                android:shadowRadius="3.0" />
    </RelativeLayout>

</FrameLayout>
4

1 回答 1

0

请尝试您的AppwidgetManager.updatewidget()方法。onupdateAppWidgetManager

于 2012-05-29T06:31:01.097 回答