android - 我要求每 3 小时后重新启动我的应用程序
问题描述
我正在开发 android 应用程序,我在其中以幻灯片放映方式显示媒体。应用程序保持 24 小时 7 小时工作,因为它用于广告目的,但有时会在几天后自动崩溃,不知道为什么,所以客户要求我每 3 小时后自动重启应用程序。每花费 3 小时它应该重新启动整个应用程序
我看过其他人对同一问题的回答,但他们不适合我
我在 MainActivity 的 onCreate 中调用此代码
PendingIntent pendingIntent = PendingIntent.getActivity(getApplicationContext(),1,restatIntent,PendingIntent.FLAG_CANCEL_CURRENT);
AlarmManager alarmManager = (AlarmManager) getApplicationContext().getSystemService(Context.ALARM_SERVICE);
alarmManager.set(AlarmManager.RTC_WAKEUP,System.currentTimeMillis() + 1000,pendingIntent);
System.exit(0);
此代码在应用程序打开后立即关闭应用程序,然后开始使用此错误使应用程序崩溃
拒绝在先前失败的类 java.lang.Class<androidx.core.view.ViewCompat$2> 上重新初始化:java.lang.NoClassDefFoundError:解析失败:Landroid/view/View$OnUnhandledKeyEventListener;
我想每隔 3 小时定期重新启动我的应用程序 任何帮助将不胜感激
解决方案
推荐阅读
- python - 在 groupby 和 reindex 之后前向填充特定列
- python - Python - 在 SQL 数据库中存储加密密钥
- c# - Xamarin.Android .Jar Binding --> 在哪里可以找到 MainActivity.cs 文件的 using 指令?
- javascript - 我们可以在父级中捕获错误但在子级中实现回退 - React Error Boundary
- spring-boot - Web3j:获取使用交易哈希传输的交易令牌的价值
- html - 为什么 col-md-3 将图像堆叠成一列
- javascript - 设置新的 chrome 创建选项卡的 localStorage
- shell - 鱼壳上的部分值为空时无法设置壳环境
- javascript - iframe 中的一些函数没有被执行
- python - 使用列表中的值查找字典键