2013년 4월 24일 수요일

사용자가 5초 동안 앱을 터치하지 않았을 경우 처리

public class hard_UserInteraction extends Activity {
 public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.hard_userinteraction);
 }

 protected Handler mFinishHandler = new Handler() {
  public void handleMessage(android.os.Message msg) {
   finish();
  }
 };

 void registerFinish() {
  mFinishHandler.sendEmptyMessageDelayed(0, 5 * 1000);
 }

 void unRegisterFinish() {
  
 }

 void RefreshFinish() {
  unRegisterFinish();
  registerFinish();
 }

 protected void onResume() {
  super.onResume();
  registerFinish();
 }

 protected void onPause() {
  super.onPause();
  unRegisterFinish();
 }

 public void onUserInteraction() {
  super.onUserInteraction();
  RefreshFinish();
 }

 protected void onUserLeaveHint () {
  super.onUserLeaveHint();
  Toast.makeText(this, "Leave by user", Toast.LENGTH_LONG).show();
 }
}
출처 : http://www.winapi.co.kr/android/annex/19-3.htm

댓글 없음:

댓글 쓰기