어플 종료 관련 소스인데요
이 기능을 하나의 클래스로 만들어서 필요할때마다 불러다 쓰고 싶은데요
어떻게 해야 되는지 모르겠어요.
힌트라도 좀 부탁드릴께요.
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
Toast.makeText(mContext, "aaa", 1).show();
//if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) {
//event.startTracking();
AlertDialog.Builder builder = new AlertDialog.Builder(((Activity)mContext));
builder.setMessage("어플리케이션을 종료하시겠습니까 ?");
builder.setCancelable(false)
.setPositiveButton("예", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
onBackPressed();
}
})
.setNegativeButton("아니오", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.cancel();
}
});
AlertDialog alert = builder.create();
alert.show();
return true;
//}
//return super.onKeyDown(keyCode, event);
//return false;
}
public void onBackPressed(){
((Activity)mContext).finish();
requestKillProcess(mContext);
}
public void requestKillProcess(Context context){
new Thread(new Runnable() {
@Override
public void run() {
ActivityManager am = (ActivityManager) mContext.getSystemService(Context.ACTIVITY_SERVICE);
String name = mContext.getApplicationInfo().processName;
RunningServiceInfo si;
//pooling the current application process importance information.
while(true){
List<RunningAppProcessInfo> list = am.getRunningAppProcesses();
for(RunningAppProcessInfo i : list){
if(i.processName.equals(name) == true){
//#4. kill the process,
//only if current application importance is less than IMPORTANCE_BACKGROUND
if(i.importance >= RunningAppProcessInfo.IMPORTANCE_BACKGROUND){
//if(i.importance >= RunningAppProcessInfo.IMPORTANCE_SERVICE){
am.restartPackage(mContext.getPackageName()); //simple wrapper of killBackgrounProcess
}else{
//finish();
Thread.yield();
}
break;
}
}
}
}
}, "Process Killer").start();
}



