• 周五. 5月 2nd, 2025

Android app 如何实现崩溃后自动重启

Android app  如何实现崩溃后自动重启

    由于有很多场景需要让自己的app一直保持运行状态,比如客户的launcher,或者定制app。 都希望在自己的app崩溃之后还可以自重启。 

    对于这样子的需求,android系统也为app量身定做了几个属性:

android:persistent="true"
android:killAfterRestore="true"

    添加方法如下(只要在AndroidManifest.xml里添加即可):

<application android:name=".NfcApplication"
             android:icon="@drawable/icon"
             android:label="@string/app_name"
             android:theme="@android:style/Theme.Material.Light"
             android:persistent="true"
             android:backupAgent="com.android.nfc.NfcBackupAgent"
             android:killAfterRestore="true"
             android:usesCleartextTraffic="false"
>

发表评论

您的电子邮箱地址不会被公开。