首页 > 解决方案 > 我要求每 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 小时定期重新启动我的应用程序 任何帮助将不胜感激

标签: androidandroid-intentalarmmanagerandroid-jobscheduler

解决方案


推荐阅读