Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Question] App with multiple processes. #1

Open
fengdai opened this issue Jul 8, 2015 · 4 comments
Open

[Question] App with multiple processes. #1

fengdai opened this issue Jul 8, 2015 · 4 comments

Comments

@fengdai
Copy link

fengdai commented Jul 8, 2015

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

@JakeWharton
Copy link
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.

@artem-zinnatullin
Copy link

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).

@JakeWharton
Copy link
Owner

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

Method overhead is too high. Cannot abide.

@rlatapy-luna
Copy link

rlatapy-luna commented Apr 3, 2024

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
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants