- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
每当我重新启动手机或升级应用程序(在我的测试设备和 Android
模拟器上)时,小部件就会停止更新,直到我创建小部件的新实例。然后小部件的两个实例将再次开始更新。我认为这是在旧的 WidgetIds
上调用 onUpdate()
造成的,但我无法弄清楚。这是我的代码的一小段。
public class NewAppWidget extends AppWidgetProvider {
private static final String refresh = "b_refresh";
static void updateAppWidget(Context context, AppWidgetManager appWidgetManager, int appWidgetId) {
RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.new_app_widget);
Intent intent = new Intent(context, NewAppWidget.class);
intent.setAction(refresh);
intent.putExtra("appWidgetId", appWidgetId);
views.setOnClickPendingIntent(R.id.refresh, PendingIntent.getBroadcast(context,0,intent, PendingIntent.FLAG_UPDATE_CURRENT));
appWidgetManager.updateAppWidget(appWidgetId, views);
}
@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
for (int appWidgetId : appWidgetIds) {
updateAppWidget(context, appWidgetManager, appWidgetId);
}
}
@Override
public void onReceive(Context context, Intent intent) {
if(refresh.equals(intent.getAction())) {
Toast.makeText(context, "Clicked2", Toast.LENGTH_LONG).show();
}
}
}
编辑:这是我的manifest.xml
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<receiver android:name=".NewAppWidget">
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
<action android:name="android.appwidget.action.EXTRA_APPWIDGET_IDS"/>
</intent-filter>
<meta-data
android:name="android.appwidget.provider"
android:resource="@xml/new_app_widget_info" />
</receiver>
<activity android:name=".NewAppWidgetConfigureActivity">
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_CONFIGURE" />
</intent-filter>
</activity>
</application>
最佳答案
将对 super.onReceive()
的调用添加到 onReceive()
中。
说明
如果你查看基类onReceive()
的源码,你会发现它实现了管理Widget生命周期的部分框架逻辑。 (也由 docs 暗示)。它处理 APPWIDGET_UPDATE
,事实上,它首先负责调用 onUpdate()
。 (例如,当系统启动时,它需要绘制您的初始小部件,它会向您的应用发送一个 APPWIDGET_UPDATE
,该消息会传递给 onReceive()
)。因此,在您的情况下,我不能 100% 确定 onUpdate()
是如何被调用的,但我假设您在其他地方有一些代码调用 updateAppWidget()
,这就是您的小部件甚至暂时可以工作的唯一原因。
关于java - 重新启动或升级应用程序后,我的 Android 小部件停止更新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52193688/
我搜索了重启我的 android 应用程序的替代方法,但我发现重启的唯一方法是使用 Flex 构建. 我可以用 as3 flash 重启我的 android adobe air 应用程序吗?我该怎么做
我有一个学校评估,是为了制作一个 child 的拼写游戏,当玩家单击"is"时,它必须循环/重新启动。到目前为止,当我测试游戏时,询问玩家是否想再次玩的选项/easygui.buttonbox 以
在.yml文件中,我定义了:restart: always。是否可以将此重启创建为--force-recreate标志的等效项? 我的XVFB有问题,标准重启无法解决问题,但通过--force-rec
我正在尝试重新启动 while 循环。我已经声明了 boolean 类型的变量 keepGoing 。如果 int 变量 x 超出窗口,则 keepGoing 更改为 false。然后reset()方
如何使用 Cast SDK 或其他方式让我的应用以官方 Chromecast 应用的方式触发 Chromecast 重启? 如果是“否则”,Google Play 可能会对这种做法不友善吗? 最佳答案
运行/etc/init.d/postgresql restart有没有危险?我们刚刚发生了一些关系“消失”的事件,我运行了上述命令。刚刚被系统管理员骂了一顿,但是他没有解释为什么这是一件坏事。我确实将
是否可以重新启动 while 循环?我目前在 foreach 循环中存在一个 while 循环,并且每次都需要 while 语句从头开始。 $sql = mysqli_query($link, "SE
我有如下倒计时器: - (void)updateCounterLabel:(NSTimer *)theTimer { if(secondsLeft > 0 ){ secondsLeft
就像我在 python 中一样。 choice1 = raw_input('John Blue Green') if choice1 == 'A': print('blah') elif cho
我的游戏在 True 循环中运行一段时间,我希望能够要求用户“再玩一次?”我已经有了用于弹出文本的矩形的代码,但我需要一种方法让用户单击矩形或按 y 表示是,然后代码再次自行运行。 最佳答案 在您的主
我是 nginx 的初学者。我正在使用 Ubuntu 16.04。我按照步骤操作, sudo apt-get 更新。 sudo apt-get install nginx sudo apt-get 升
我需要使用 javascript 重放一个 css 转换。当我重置我的 div 的 css 样式并应用新的过渡时,没有任何反应...... 我认为这两个代码是在同一个执行框架中执行的,并且通过优化,它
所以我有这几行代码: string[] newData = File.ReadAllLines(fileName) int length = newData.Length; for (int i =
所以我有一个计时器,每 5 秒旋转一组图像。因此,我在文档启动时运行它。 $(document).ready(function() { var intervalID=setInterval(funct
好吧,我在重新启动 Apache 服务器时遇到了一些问题。我修改了服务器上的 ulimit 但我无法重新启动 httpd; 我在 CentOS 5.8 x64 上运行服务器. httpd -V 的输出
我在使用 docker 时遇到问题 docker ps不会返回并被卡住。 我发现做 docker service restart 之类的sudo service docker restart (htt
从 .net 代码停止和重新启动 Storyboard的正确方法是什么? 我想 ... myStory.Stop(this); 期望随后调用 .Begin(this);将从零开始从时间线重新开始,但
我有一个带有一些缓存后端的应用程序,我想在重新启动网络服务器时清除缓存。 在网络服务器(重新)启动时是否有 apache 配置指令或任何其他方式来执行 shell 脚本? 谢谢, 菲尔 正如一些答案已
我愿意在我的应用程序中添加一个按钮,单击该按钮将重新启动应用程序。我搜索了谷歌,但发现除了 this one 没有任何帮助.但是这里遵循的程序违反了 Java 的 WORA 概念。 是否还有其他以 J
我们目前遇到间歇性邮件队列中断。我是 seeking diagnostic help in another area . 同时,有没有办法在不重启整个服务的情况下重启CF邮件队列? CF8标准 Win
我是一名优秀的程序员,十分优秀!