How to restart an application completely?

前端 未结 7 1578
长发绾君心
长发绾君心 2021-01-04 17:35

I have an application which starts a Remote Service in its first launched activity. Then, in another activity, the user can set the configuration of the application. Please

7条回答
  •  Happy的楠姐
    2021-01-04 18:27

    Solution of AlarmManager can not work because on kill app all pending intents can be removed. On android-10 I have this issue.

    But I found other way - create Instrumentation class and call startInstrumentation on Context. Worked very nice.

    boolean android.content.Context.startInstrumentation(ComponentName className, String profileFile, Bundle arguments)

    Start executing an android.app.Instrumentation class. The given Instrumentation component will be run by killing its target application (if currently running), starting the target process, instantiating the instrumentation component, and then letting it drive the application.

    This function is not synchronous -- it returns as soon as the instrumentation has started and while it is running.

    Instrumentation is normally only allowed to run against a package that is either unsigned or signed with a signature that the the instrumentation package is also signed with (ensuring the target trusts the instrumentation).

    Instrumentation must be defined in manifest. Google how use it.

提交回复
热议问题