gpt4 book ai didi

android - 小部件在旋转(垂直到水平)时崩溃

转载 作者:行者123 更新时间:2023-12-02 07:04:10 27 4
gpt4 key购买 nike

美好的一天。我有一个带有图像按钮的小部件。我正在尝试使用以下代码在按钮上设置图像,但我的小部件在旋转时崩溃!你有什么想法吗?

  @Override
public void onReceive(Context context, Intent intent)
{
RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.widget);
remoteViews.setImageViewResource(R.id.imageButton, MyNewimageID);

ComponentName thisWidget = new ComponentName(context, MyWidget.class);
AppWidgetManager manager = AppWidgetManager.getInstance(context);
manager.updateAppWidget(thisWidget, remoteViews);
}

最佳答案

我找到了解决方案

Intent active = new Intent(context, MyWidget.class);
active.setAction(ACTION_WIDGET_RECEIVER);
PendingIntent actionPendingIntent = PendingIntent.getBroadcast(context, 0, active, 0); remoteViews.setOnClickPendingIntent(R.id.imagebuttonButton, actionPendingIntent);
manager.updateAppWidget(thisWidget, remoteViews);

关于android - 小部件在旋转(垂直到水平)时崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13550577/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com