Android 应用重启 - 不适用于 Android 11

问题描述

重新启动应用程序:完成如下:

   fun restartApp(context: Context) {
    try {
        val mStartActivity = Intent(context,SplashActivity::class.java)
        val mPendingIntentId = 123456
        val mPendingIntent: PendingIntent = PendingIntent.getActivity(context,mPendingIntentId,mStartActivity,PendingIntent.FLAG_CANCEL_CURRENT)
        val mgr: AlarmManager = context.getSystemService(Context.ALARM_SERVICE) as AlarmManager
        mgr.set(AlarmManager.RTC,System.currentTimeMillis() + 500,mPendingIntent)
        System.exit(0)
    } catch (e: java.lang.Exception) {
        e.printStackTrace()
    }
}

然后尝试如下:

Intent i = getBaseContext().getPackageManager().getLaunchIntentForPackage( getBaseContext().getPackageName() );
i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(i);

但是,没有成功。

我正在更新 BLE 设备中的固件,成功写入后,我需要完全重新启动应用程序。 实施了上述两种方法,但没有成功。

我想清除所有分配的值,并且必须重新启动应用程序,即不仅仅是启动新活动。

我怎样才能做到这一点?谢谢。

注意:这个问题有很多解决方案,但可能是针对 Android 11 的。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...