package kr.co.compcareworker.Util;

import android.app.Activity;

import kr.co.compcareworker.MyApplication;

public class TerminateThread extends Thread {
    private boolean isRun = true;
    private static int SLEEP = 60000;

    public TerminateThread() {
    }

    public void stopForever() {
        synchronized (this) {
            this.isRun = false;
        }
    }

    public void run() {

        while (isRun) {

            try {
                Thread.sleep(SLEEP);
            } catch (InterruptedException e) {
                e.printStackTrace();
                break;
            }

            if (MyApplication.myActivity != null){
                MyApplication.myActivity.setResult(Activity.RESULT_CANCELED);
                MyApplication.myActivity.finishAffinity();
            } else {
                System.runFinalization();
                System.exit(0);
            }
        }
        interrupt();
    }
}
