Java tutorial
//package com.java2s; import java.lang.reflect.Field; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import android.app.Activity; public class Main { @Deprecated public static void quitAppliation(Activity activity) { try { Class<?> clazz_Activity = Class.forName("android.app.Activity"); Field field_mMainThread = clazz_Activity.getDeclaredField("mMainThread"); field_mMainThread.setAccessible(true); Object mMainThread = field_mMainThread.get(activity); Class<?> clazz_ActivityThread = Class.forName("android.app.ActivityThread"); Field field_mAppThread = clazz_ActivityThread.getDeclaredField("mAppThread"); field_mAppThread.setAccessible(true); Object mAppThread = field_mAppThread.get(mMainThread); Class<?> clazz_ActivityClientRecord = Class.forName("android.app.ActivityThread$ApplicationThread"); Method method_scheduleExit = clazz_ActivityClientRecord.getDeclaredMethod("scheduleExit"); method_scheduleExit.invoke(mAppThread); } catch (NoSuchFieldException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } catch (IllegalArgumentException e) { e.printStackTrace(); } catch (ClassNotFoundException e) { e.printStackTrace(); } catch (NoSuchMethodException e) { e.printStackTrace(); } catch (InvocationTargetException e) { e.printStackTrace(); } } }