本文整理了Java中android.os.Process.killProcess()
方法的一些代码示例,展示了Process.killProcess()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Process.killProcess()
方法的具体详情如下:
包路径:android.os.Process
类名称:Process
方法名:killProcess
暂无
代码示例来源:origin: greenrobot/EventBus
public void onClickKillProcess(View view) {
Process.killProcess(Process.myPid());
}
代码示例来源:origin: ACRA/acra
private void killProcessAndExit() {
Process.killProcess(Process.myPid());
System.exit(10);
}
}
代码示例来源:origin: android-hacker/VirtualXposed
@Override
public void killApplicationProcess(final String processName, int uid) {
synchronized (mProcessNames) {
ProcessRecord r = mProcessNames.get(processName, uid);
if (r != null) {
killProcess(r.pid);
}
}
}
代码示例来源:origin: gzu-liyujiang/AndroidPicker
/**
* 退出软件
*/
public void exitApp() {
clearActivitiesAndServices();
android.os.Process.killProcess(android.os.Process.myPid());
System.exit(0);//normal exit application
}
代码示例来源:origin: Tencent/tinker
public static void killAllOtherProcess(Context context) {
final ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
if (am == null) {
return;
}
List<ActivityManager.RunningAppProcessInfo> appProcessList = am
.getRunningAppProcesses();
if (appProcessList == null) {
return;
}
// NOTE: getRunningAppProcess() ONLY GIVE YOU THE PROCESS OF YOUR OWN PACKAGE IN ANDROID M
// BUT THAT'S ENOUGH HERE
for (ActivityManager.RunningAppProcessInfo ai : appProcessList) {
// KILL OTHER PROCESS OF MINE
if (ai.uid == android.os.Process.myUid() && ai.pid != android.os.Process.myPid()) {
android.os.Process.killProcess(ai.pid);
}
}
}
代码示例来源:origin: Tencent/tinker
public static void killTinkerPatchServiceProcess(Context context) {
String serverProcessName = getTinkerPatchServiceName(context);
if (serverProcessName == null) {
return;
}
final ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
// ActivityManager getRunningAppProcesses()
List<ActivityManager.RunningAppProcessInfo> appProcessList = am
.getRunningAppProcesses();
if (appProcessList == null) {
return;
}
for (ActivityManager.RunningAppProcessInfo appProcess : appProcessList) {
String processName = appProcess.processName;
if (processName.equals(serverProcessName)) {
android.os.Process.killProcess(appProcess.pid);
}
}
}
代码示例来源:origin: JessYanCoding/MVPArms
/**
* 退出应用程序
* <p>
* 此方法经测试在某些机型上并不能完全杀死 App 进程, 几乎试过市面上大部分杀死进程的方式, 但都发现没卵用, 所以此
* 方法如果不能百分之百保证能杀死进程, 就不能贸然调用 {@link #release()} 释放资源, 否则会造成其他问题, 如果您
* 有测试通过的并能适用于绝大多数机型的杀死进程的方式, 望告知
*/
public void appExit() {
try {
killAll();
android.os.Process.killProcess(android.os.Process.myPid());
System.exit(0);
} catch (Exception e) {
e.printStackTrace();
}
}
代码示例来源:origin: Tencent/tinker
public static void killProcessExceptMain(Context context) {
final ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
if (am == null) {
return;
}
List<ActivityManager.RunningAppProcessInfo> appProcessList = am.getRunningAppProcesses();
if (appProcessList != null) {
// NOTE: getRunningAppProcess() ONLY GIVE YOU THE PROCESS OF YOUR OWN PACKAGE IN ANDROID M
// BUT THAT'S ENOUGH HERE
for (ActivityManager.RunningAppProcessInfo ai : appProcessList) {
if (ai.uid != android.os.Process.myUid()) {
continue;
}
if (ai.processName.equals(context.getPackageName())) {
continue;
}
android.os.Process.killProcess(ai.pid);
}
}
}
代码示例来源:origin: Rukey7/MvpApp
/**
* you can restart your process through service or broadcast
*/
private void restartProcess() {
TinkerLog.i(TAG, "app is background now, i can kill quietly");
//you can send service or broadcast intent to restart your process
android.os.Process.killProcess(android.os.Process.myPid());
}
代码示例来源:origin: Marswin/MarsDaemon
@Override
public void onDaemonAssistantCreate(Context context, DaemonConfigurations configs) {
Intent intent = new Intent();
ComponentName component = new ComponentName(context.getPackageName(), configs.PERSISTENT_CONFIG.SERVICE_NAME);
intent.setComponent(component);
context.startService(intent);
if(configs != null && configs.LISTENER != null){
configs.LISTENER.onWatchDaemonDaed();
}
android.os.Process.killProcess(android.os.Process.myPid());
}
代码示例来源:origin: Marswin/MarsDaemon
@Override
public void onDaemonDead() {
mAlarmManager.setRepeating(AlarmManager.ELAPSED_REALTIME, SystemClock.elapsedRealtime(), 100, mPendingIntent);
android.os.Process.killProcess(android.os.Process.myPid());
}
代码示例来源:origin: Marswin/MarsDaemon
@Override
public void onDaemonAssistantCreate(Context context, DaemonConfigurations configs) {
Intent intent = new Intent();
ComponentName component = new ComponentName(context.getPackageName(), configs.PERSISTENT_CONFIG.SERVICE_NAME);
intent.setComponent(component);
context.startService(intent);
if(configs != null && configs.LISTENER != null){
configs.LISTENER.onWatchDaemonDaed();
}
android.os.Process.killProcess(android.os.Process.myPid());
}
代码示例来源:origin: libgdx/libgdx
void pause () {
synchronized (synch) {
if (!running) return;
running = false;
pause = true;
while (pause) {
try {
// TODO: fix deadlock race condition with quick resume/pause.
// Temporary workaround:
// Android ANR time is 5 seconds, so wait up to 4 seconds before assuming
// deadlock and killing process. This can easily be triggered by opening the
// Recent Apps list and then double-tapping the Recent Apps button with
// ~500ms between taps.
synch.wait(4000);
if (pause) {
// pause will never go false if onDrawFrame is never called by the GLThread
// when entering this method, we MUST enforce continuous rendering
Gdx.app.error(LOG_TAG, "waiting for pause synchronization took too long; assuming deadlock and killing");
android.os.Process.killProcess(android.os.Process.myPid());
}
} catch (InterruptedException ignored) {
Gdx.app.log(LOG_TAG, "waiting for pause synchronization failed!");
}
}
}
}
代码示例来源:origin: libgdx/libgdx
void pause () {
synchronized (synch) {
if (!running) return;
running = false;
pause = true;
while (pause) {
try {
// TODO: fix deadlock race condition with quick resume/pause.
// Temporary workaround:
// Android ANR time is 5 seconds, so wait up to 4 seconds before assuming
// deadlock and killing process. This can easily be triggered by opening the
// Recent Apps list and then double-tapping the Recent Apps button with
// ~500ms between taps.
synch.wait(4000);
if (pause) {
// pause will never go false if onDrawFrame is never called by the GLThread
// when entering this method, we MUST enforce continuous rendering
Gdx.app.error(LOG_TAG, "waiting for pause synchronization took too long; assuming deadlock and killing");
android.os.Process.killProcess(android.os.Process.myPid());
}
} catch (InterruptedException ignored) {
Gdx.app.log(LOG_TAG, "waiting for pause synchronization failed!");
}
}
}
}
代码示例来源:origin: Marswin/MarsDaemon
@Override
public void onDaemonDead() {
mAlarmManager.setRepeating(AlarmManager.ELAPSED_REALTIME, SystemClock.elapsedRealtime(), 100, mPendingIntent);
if(mConfigs != null && mConfigs.LISTENER != null){
mConfigs.LISTENER.onWatchDaemonDaed();
}
android.os.Process.killProcess(android.os.Process.myPid());
}
代码示例来源:origin: android-hacker/VirtualXposed
@Override
public void killAllApps() {
synchronized (mPidsSelfLocked) {
for (int i = 0; i < mPidsSelfLocked.size(); i++) {
ProcessRecord r = mPidsSelfLocked.valueAt(i);
killProcess(r.pid);
}
}
}
代码示例来源:origin: Marswin/MarsDaemon
@Override
public void onDaemonDead() {
if(startServiceByAmsBinder()){
if(mConfigs != null && mConfigs.LISTENER != null){
mConfigs.LISTENER.onWatchDaemonDaed();
}
android.os.Process.killProcess(android.os.Process.myPid());
}
}
代码示例来源:origin: Marswin/MarsDaemon
@Override
public void onDaemonDead() {
if(sendBroadcastByAmsBinder()){
if(mConfigs != null && mConfigs.LISTENER != null){
mConfigs.LISTENER.onWatchDaemonDaed();
}
android.os.Process.killProcess(android.os.Process.myPid());
}
}
代码示例来源:origin: android-hacker/VirtualXposed
public static <T> T crash(RemoteException e) throws RuntimeException {
e.printStackTrace();
if (VirtualCore.get().isVAppProcess()) {
Process.killProcess(Process.myPid());
System.exit(0);
}
throw new DeadServerException(e);
}
代码示例来源:origin: Tencent/tinker
/**
* rollback patch should restart all process
*/
public void rollbackPatch() {
if (!isTinkerLoaded()) {
TinkerLog.w(TAG, "rollbackPatch: tinker is not loaded, just return");
return;
}
// kill all other process
ShareTinkerInternals.killAllOtherProcess(context);
// clean patch
cleanPatch();
// kill itself
android.os.Process.killProcess(android.os.Process.myPid());
}
/**
内容来源于网络,如有侵权,请联系作者删除!