2012-06-20 4 views
1

내 목표는 사용자가 내 앱으로 돌아갈 때 모달 대화 상자를 표시하는 것입니다. 이 모달 대화 상자는 정의 된 6 자리 PIN을 묻습니다. 나는 Java GUI와 안드로이드 개발에 익숙하기 때문에 문제는 .....Android 모달 대화 상자 스태킹

Enterpin 대화 상자가 표시되는 동안 사용자가 응용 프로그램을 최소화하도록 선택하면 대화 상자 스택을 앱에 반환하면 서로 위에. PIN을 입력하는 동안 최소화 한 횟수만큼 PIN을 입력하고 앱으로 돌아갑니다.

/** 
* On restart called when the app is being restarted on the screen 
*/ 
@Override 
public void onRestart() { 
    super.onRestart(); 



    // must prompt with modal dialog for pin 

    final Dialog dialog = new Dialog(this); 

    dialog.setCancelable(false); 

    // check pin 
    dialog.setCanceledOnTouchOutside(false); 
    // set view to enterpin XML screen 
    dialog.setContentView(R.layout.enterpin); 


    // show dialog 
    if (!dialog.isShowing()) { 
     dialog.show(); 
    } 
    // listen for button being clicked 
    Button button = (Button) dialog.findViewById(R.id.pinlogin); 
    button.setOnClickListener(new OnClickListener() {// anonymous inner 
     // class 
     // implementation 
     @Override 
     public void onClick(View v) { 
      EditText editText = (EditText) dialog 
        .findViewById(R.id.enterpintext); 
      try { 
       int enteredPin = Integer.parseInt(editText.getText() 
         .toString()); 
       SharedPreferences sharedP = Prefs.get(WebViewActivity.this); 
       int temp = sharedP.getInt("pin", 0); 
       if (enteredPin == temp) { 
        pinCheck = true; 



        dialog.dismiss(); 
       } else { 
        pinCheck = false; 
        dialog.setTitle("Incorrect Pin"); 
       } 
      } catch (NumberFormatException e) { 
       Dialog dialog2 = new Dialog(WebViewActivity.this); 
       dialog2.setTitle("Enter Numbers Only"); 
       dialog2.setCanceledOnTouchOutside(true); 
       dialog2.show(); 
      } 
     } 
    }); 

} 

어딘가에 프로그래밍 방식이 좋지 않은데도 대화 초기화를 옮길 수 있습니까? 대화 상자 인스턴스가 메서드의 수명 동안 존재하기 때문에 내가 시도한 dialog.isShowing() 메서드가 작동하지 않는 이유를 이해합니다.

휴대 전화를 세로 방향에서 가로 방향으로 90도 돌리면 어쨌든 대화 상자가 사라집니다. 누군가가 강제로 다시 그리기를 할 때 호출되는 메서드 체인을 지적하여 대화 상자를 다시 그릴 수 있습니까?

protected android.app.Dialog onCreateDialog(int id) { 
     if (this.currentDialog != null) { 
      this.currentDialog.dismiss(); 
     } 

     this.currentDialog = null; 

     switch (id) { 
      case DIALOG_SPINNER: 
       ProgressDialog progressDialog = new ProgressDialog(this); 
       progressDialog.setMessage(getString(R.string.dialog_Spinner_UpdatingAccount)); 
       progressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER); 

       this.currentDialog = progressDialog; 
       break; 
     } 

     return this.currentDialog; 

    } 

나는 또한 폐기 :

+0

코드가 내 문제를 해결했습니다 : setCanceledOnTouchOutside가 호출되었습니다. 그러나, 나는 Dialog 대신 Activity를 서브 클래스 화했다. 이 경우 호출은 setFinishOnTouchOutside입니다. 그것은 android : theme = "@ android : style/Theme.Dialog"와 함께 사용하면 대화처럼 행동을합니다. –

답변

2

나는 onResume(); + onPause();을 찾고 onRestart();이 아닌 대화 상대를 찾고 있다고 생각합니다. PIN 대화 상자가 표시되지만 대화 상자를 만들지 않기위한 플래그를 설정하려면 onRestart();을 사용해야합니다.

onCreate(); 메서드로 옮기고 작업중인 속성을 속성으로 만들고 onResume(); 메서드에 표시하면됩니다 (활성 상태가 활성화 될 때마다 항상 호출되므로, 심지어 처음으로).

오리엔테이션 변경시 오리엔테이션 변경 이벤트 (활성 매니페스트의 android:configChanges="orientation" 경유)를 듣고 싶은 경우 해당하는 데이터가있는 활성 활동에서 onConfigurationChanged(); 메소드가 호출되어야합니다. 그런 다음 대화 상자를 새로운 방향으로 다시 그릴 수 있습니다.

1

는 내가 대화 상자를 표시 할 때마다, 나는이 라인을 따라 뭔가를 사용하는 작업의 속성 대화로 저장하여 같은 문제 (핀 항목 또는 기타)를 해결하기 액티비티가 스택의 맨 위에 놓일 때의 현재 대화 상자 (탐색 또는 종료).

@Override 
    public void onPause() { 
     if (this.currentDialog != null) { 
      this.currentDialog.dismiss(); 
     } 

     super.onPause(); 
    } 

onPause 방법을 사용하면 활동을 일시 정지 할 때 이미 열려있는 대화, 기존 onRestart 코드 그냥 새 대화 상자를 표시 할 그런 식으로 해고 할 수 있습니다.