앱을 홈키를 눌러서 백그라운드로 갔다가 포그라운드로 올라오는 때를 알수 있는 방법이 있을까요?
Activity에서 onStop과 onResume를 이용하려고 해도 Activity가 수십개가 되고 있습니다.
특히 홈으로 나갔던게 아니라. 상위 엑티비티에서 하위 엑티비티로 복귀를 할때도 똑같이 불리는데요.
꼼수를 써서 가능은 할듯 하나..
아이폰처럼 명확한 이벤트 가 필요한 상황입니다.
알려주시면 감사하겠습니다.
프로세스상태를 로그로확인해보면 onPause 오버라이딩시킨데다가
/** 최하위스텍 액티비티알아내기 */
public static String getBaseActivityName(Context context) {
ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
List<RunningTaskInfo> info;
info = activityManager.getRunningTasks(1);
// context.getClass().getName()
// or
// String activityName = info.get(0).baseActivity.getClassName();
String activityName = info.get(0).baseActivity.getClassName();
int lastindex = activityName.lastIndexOf(".");
return activityName.substring(lastindex + 1, activityName.length());
}
를 호출해서 로그로 찍어보시면 홈버튼을 누를때 onPause에서 Luncher가뜨는걸 알수있습니다.
그것을이용해서
@Override
protected void onRestart() {
// TODO Auto-generated method stub
super.onRestart();
if (getLock()) {
if (activityName.equals("Launcher") || activityName.equals("HomeActivity")) {
Intent intent = new Intent(LockActivity.this, AppLockSetup.class);
// intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
intent.putExtra("mode", "start");
intent.putExtra("LockActivity", "backfinish");
startActivity(intent);
}
}
}
뭐이런식으로줍니다..
참고로 똥폰들같은경우에는 Luncher말고 (모토믹스=HomeActivity같은게호출)될수있으니 참고바랍니다.
클래스 하나 파셔서... 플래그값이나 전역값등으로 특정한 케이스를 만들어서... setType() 처럼 메소드 만드셔서
전역값을 설정해서 특히점을 주는 방법밖에 없을것 같은데요..