package android.SosTimer;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.os.Handler;
import android.view.View;
import android.view.WindowManager;
import android.widget.EditText;
import android.widget.LinearLayout;
public class WrongPW extends Activity {
 
 public static final String KEY_MY_PREFERENCE = "my_preference";
 public static final String KEY_TERM_PREFERENCE = "term_preference";
 final static int RESULT_NOT = 1;
 /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
                | WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD
                | WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON
                | WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON);
        requestWindowFeature(android.view.Window.FEATURE_NO_TITLE);   
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);   
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_BLUR_BEHIND, WindowManager.LayoutParams.FLAG_BLUR_BEHIND); 
        setContentView(R.layout.write_pw); 
        
        Handler mHandler = new Handler();
        mHandler.postDelayed(new Runnable(){
         @Override
         public void run() {
          Intent iSms = new Intent(WrongPW.this, SendSms.class);
          startActivity(iSms);
          finish();
         }
        }, 60*1000);
        
        final LinearLayout linear = (LinearLayout)View.inflate(this, R.layout.write_pw, null);
        
        new AlertDialog.Builder(this)
        .setTitle("비밀번호를 입력하세요.")
        .setView(linear)
        .setPositiveButton("확인",new DialogInterface.OnClickListener() {
             
   @Override
   public void onClick(DialogInterface dialog, int whichButton) {
    // TODO Auto-generated method stub
    SharedPreferences pref = getSharedPreferences("PrefTest", 0);
    int pw = pref.getInt("StPass", 0);
    
    EditText textPW = (EditText)linear.findViewById(R.id.pw);
    String pwSting = textPW.getText().toString();
    int edpw = Integer.parseInt(textPW.getText().toString());
    
    if(pw==edpw) {
     Intent result = new Intent(WrongPW.this, Timer.class);
     result.putExtra("wrongresult", true); 
     setResult(2,result);
     finish();
     
    }
    else if(pw!=edpw){
      
      if(pw==edpw) {
       Intent result = new Intent(WrongPW.this, Timer.class);
       result.putExtra("wrongresult", true); 
       setResult(2,result);
       finish();
      }
      else if(pw!=edpw){
       Intent result = new Intent(WrongPW.this, Timer.class);
       result.putExtra("wrongresult", false); 
       setResult(2,result);
       finish();
      }
    }
   }
        }).show();
 
    }
} 

 

60초동안 아무 일도 일어나지 않으면 이 엑티비티에서 다른 엑티비티로 넘어가고 싶어서 Handler를 사용했습니다.

그런데 문제는

액티비티에속해있는 다이어로그에서 비밀번호를 잘못 입력하거나, 알람 종료가 되지 않았을시 여러번 이 액티비티를 띄워야하는데, 처음 액티비티가 실행됐을때부터 60초가 지나면 계속 실행중인데도 불구하고 다른 액티비티로 넘어가 버립니다.

그리구 이 프로그램이 종료되었을때도 다른 액티비티를 계속 띄우는데요.

 

아마 Handler종료를 하지 않아서 그런거 같은데 Handler를 종료할 수 있는 방법 있나요?

아니면 다른 문제인가요?