窗口小部件不显示电话重启后向上 [英] Widget Not showing up after phone restart
问题描述
我创建,直到我重新启动手机的伟大工程的窗口小部件,那么窗口小部件不显示它是无形的,但如果我持有,然后点击我可以在垃圾扔了吧
I created a widget that works great until I restart the phone, then the widget doesn't display it is invisible but if i hold and click i can throw it in the garbage
我有一个是从,做下面我widgetprovider我的配置活动调用的函数:
I have a function that is called from my configure activity in my widgetprovider that does the following:
static void updateAppWidget(Context context, AppWidgetManager appWidgetManager,
int appWidgetId, int version)
{
if(savedType == -1)
savedType = version;
// android.os.Debug.waitForDebugger();
RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.main);
Intent configIntent = new Intent(context, Configure.class);
configIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
Uri data = Uri.withAppendedPath(
Uri.parse(appWidgetId + "://widget/id/")
,String.valueOf(appWidgetId));
configIntent.setData(data);
PendingIntent pendingIntent = PendingIntent.getActivity
(context, 0, configIntent,
PendingIntent.FLAG_UPDATE_CURRENT);
views.setOnClickPendingIntent(R.id.MainImage,pendingIntent);
views.setImageViewResource(R.id.MainImage, lv_images[version]);
appWidgetManager.updateAppWidget(appWidgetId, views);
}
我有我的onUpdate没有做任何事情,因为从来就没有什么更新,但认为这将手机重启我复制了code,我不得不在功能后调用
I had my onUpdate not doing anything because there is never anything to update but thinking this would be called after a phone restart i copied the code i had in the function
for(int i = 0; i < appWidgetIds.length; ++i)
{
updateAppWidget(context, appWidgetManager, appWidgetIds[i], savedType);
}
但这似乎并没有得多要么做....建议?
but this didn't seem to do much either.... suggestions?
推荐答案
在手机重启,这反而的onUpdate的调用onEnable。
When phone restart, it will call onEnable instead of onUpdate.
- 更新 -
int[] allids = AppWidgetManager
.getInstance(Context)
.getAppWidgetIds(new ComponentName(Context, YourAppWidgetProvider.class);
这将得到所有ID是YourAppWigetProvider的的的的控制之下。了解更多关于这个
This will get all ids that is under the control of YourAppWigetProvider. Read more on this
这篇关于窗口小部件不显示电话重启后向上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!