메인에서 다른 액티비티를 불러와 popupwindow를 띄우고 있습니다. 원래 popup된 화면 레이아웃에 설정해 놓은 버튼을 눌러야 alarm이 종료되도록 설정했습니다만, 이것을 Back 버튼을 눌러도 꺼질 수 있도록 바꾸려고 하고 있습니다. 그런데 이게 이상하게도 레이아웃에 있는 버튼은 눌렀을 때 finish()를 통해 정상적으로 activity까지 종료되는데, Back 버튼을 누르면
W/InputEventReceiver: Attempted to finish an input event but the input event receiver has already been disposed.
라는 경고 메시지가 뜨면서 팝업 윈도우만 종료되고 activity는 꺼지질 않는군요;;
코드는 다음과 같습니다. 어디에서 잘못된 건가요?
public class AlarmPopup extends AppCompatActivity {
PopupWindow popup;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Handler handler = new Handler();
final Runnable r = new Runnable() {
public void run() {
onShowPopup();
}
};
handler.postDelayed(r, 500);
}
public void onShowPopup() {
LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
final View view = inflater.inflate(R.layout.alarm_popup, null);
popup = new PopupWindow(view, LinearLayout.LayoutParams.MATCH_PARENT,
LinearLayout.LayoutParams.MATCH_PARENT, true);
popup.setBackgroundDrawable(new BitmapDrawable());
popup.showAtLocation(view, Gravity.CENTER, 0, 0);
view.findViewById(R.id.button).setOnClickListener(mClickListener);
}
Button.OnClickListener mClickListener = new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent i = new Intent(AlarmPopup.this, AlarmService.class);
stopService(i);
popup.dismiss();
finish();
}
};
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK) {
Intent i = new Intent(AlarmPopup.this, AlarmService.class);
stopService(i);
popup.dismiss();
finish();
return true;
}
return super.onKeyDown(keyCode, event);
}
}