Skip to content

[Question] App with multiple processes. #1

Description

@fengdai

I have an application which components are running in two separated processes. Can ProcessPhoenix kill both of the processes at the same time?

Activity

  1. JakeWharton commented on Jul 8, 2015

    @JakeWharton
    Owner

    What are the two processes? An activity and a service?

    Right now we can only kill the process in which the method was called and we can only restart activity processes.

  2. artem-zinnatullin commented on Jul 13, 2015

    @artem-zinnatullin

    It should be possible to kill all app's processes via BroadcastReceiver which should be started in Application.onCreate() and call Runtime.getRuntime().exit(0) if it catches required intent -> every app's process will catch this broadcast and all of them will be destroyed.

    Also, what about scheduling relaunch of the process via AlarmManager with some delay? I am afraid that calling Runtime.getRuntime().exit(0) (BTW, you can use System.exit(0) which calls Runtime.getRuntime.exit()) might not be fast enough and because you are actually starting default activity or some user intent before calling exit(0) and VM can try to launch it before calling exit(0) -> undefined behavior (there is a chance that process will be killed, but new activity won't start, at least I saw such reports in question about app restart on SO).

  3. JakeWharton commented on Jul 14, 2015

    @JakeWharton
    Owner

    BTW, you can use System.exit(0) which calls Runtime.getRuntime.exit()

    Method overhead is too high. Cannot abide.

  4. rlatapy-luna commented on Apr 3, 2024

    @rlatapy-luna

    I'm using the code below to kill other processes, does it look ok @JakeWharton ? Maybe we could optionally do it in the ProcessPhoenix directly?

    /**
     * Wrapper around [ProcessPhoenix] to support multi-process kill
     */
    object OSProcessPhoenix {
        /**
         * Kill others processes then call [ProcessPhoenix.triggerRebirth]
         *
         * @see ProcessPhoenix.triggerRebirth
         */
        fun triggerRebirth(context: Context) {
            val am = context.getSystemService(ACTIVITY_SERVICE) as ActivityManager
            val processesInfo = am.runningAppProcesses
            processesInfo?.forEach { process ->
                if (process.pid != Process.myPid()) {
                    Process.killProcess(process.pid)
                }
            }
    
            ProcessPhoenix.triggerRebirth(context)
        }
    }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions