我正在开发 android appwidget,定期更新 appwidget 时出现问题。更新周期改为30多分钟。仍然没有更新小部件
public class MyWidgetProvider extends AppWidgetProvider {
final static String ITEM_CLICK_ACTION = "ItemClick";
public static final String TOAST_ACTION = "TOAST_ACTION";
BroadcastReceiver receiver;
public void onUpdate(Context context, AppWidgetManager appWidgetManager,
int[] appWidgetIds) {
final int N = appWidgetIds.length;
for (int i = 0; i < N; i++) {
int appWidgetId = appWidgetIds[i];
Log.e("called", "omupdate");
RemoteViews views = new RemoteViews(context.getPackageName(),
R.layout.widget_lay);
views.setTextViewText(R.id.textView1,
"Floating Text will be displayed here .. Daily Thoughts");
Intent intent = new Intent(context, RemoteServiceEmin.class);
intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
// intent.setData(Uri.parse(intent.toUri(Intent.URI_INTENT_SCHEME)));
views.setRemoteAdapter(R.id.gridview, intent);
// inflating list remote view
Intent intentlist = new Intent(context, ListInflater.class);
intentlist.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID,
appWidgetId);
// intent.setData(Uri.parse(intent.toUri(Intent.URI_INTENT_SCHEME)));
views.setRemoteAdapter(R.id.listview, intentlist);
// setting onclick on gridview
Intent itemClickIntent = new Intent(context, MyWidgetProvider.class);
itemClickIntent.setAction(ITEM_CLICK_ACTION);
itemClickIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID,
appWidgetIds[i]);
PendingIntent itemClickPendingIntent = PendingIntent.getBroadcast(
context, 0, itemClickIntent,
PendingIntent.FLAG_UPDATE_CURRENT);
views.setPendingIntentTemplate(R.id.gridview,
itemClickPendingIntent);
Intent toastIntent = new Intent(context, MyWidgetProvider.class);
toastIntent.setAction(MyWidgetProvider.TOAST_ACTION);
toastIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID,
appWidgetIds[i]);
intent.setData(Uri.parse(intent.toUri(Intent.URI_INTENT_SCHEME)));
PendingIntent toastPendingIntent = PendingIntent.getBroadcast(
context, 0, toastIntent, PendingIntent.FLAG_UPDATE_CURRENT);
views.setPendingIntentTemplate(R.id.ll, toastPendingIntent);
// appWidgetManager.updateAppWidget(appWidgetIds[i], v);
// appWidgetManager.updateAppWidget(appWidgetIds[i], views);
appWidgetManager.updateAppWidget(appWidgetId, views);
}
super.onUpdate(context, appWidgetManager, appWidgetIds);
}
@Override
public void onReceive(Context context, Intent intent) {
// TODO Auto-generated method stub
if (intent.getAction().equals(ITEM_CLICK_ACTION)) {
Bundle extras = new Bundle();
extras.putString("text", intent.getExtras().getString("text"));
Intent actIntent = new Intent();
actIntent.setClass(context, ConfigurationActivity.class);
actIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
actIntent.putExtras(extras);
context.startActivity(actIntent);
} else if (intent.getAction().equals(TOAST_ACTION)) {
Toast.makeText(context, "dfjdsfl", Toast.LENGTH_SHORT).show();
} else {
super.onReceive(context, intent);
}
}
}
这是我的 appwidget 类,我无法追踪为什么它之后没有更新
android:updatePeriodMillis="50000"
提前致谢 ..