onActivityResult로 돌아올때 Dialog표시시 IllegalStateException

04-07 21:37:35.347: E/vpb(30701): java.lang.IllegalStateException: Can not perform this action after onSaveInstanceState 04-07 21:37:35.347: E/vpb(30701): at android.support.v4.app.FragmentManagerImpl.checkStateLoss(FragmentManager.java:1343) 04-07 21:37:35.347: E/vpb(30701): at android.support.v4.app.FragmentManagerImpl.enqueueAction(FragmentManager.java:1361) 04-07 21:37:35.347: E/vpb(30701): at android.support.v4.app.BackStackRecord.commitInternal(BackStackRecord.java:595) 04-07 21:37:35.347: E/vpb(30701): at android.support.v4.app.BackStackRecord.commit(BackStackRecord.java:574) 04-07 21:37:35.347: E/vpb(30701): at android.support.v4.app.DialogFragment.show(DialogFragment.java:127) 04-07 21:37:35.347: E/vpb(30701): at jp.co.ais.game.vpb2014.MainActivity.showAlertDialog(MainActivity.java:904) 여러가지 사이트를 많이 찾아보았으나 결국 아래로 해결.. 즉, 결론은 Activity의 onResume후에 처리해야지 에러가 발생안함.

	private List<Runnable> queue = new ArrayList<Runnable>();
	@Override
	protected void onActivityResult(int requestCode, int resultCode, final Intent data) {
		if (requestCode == 1001) {
			// Google In-App 결제 결과
			queue.add(new Runnable() {
				@Override
				public void run() {
					// 여기에서 다이얼로그를 표시
				}
			});
			return;
		}
	}
	@Override
	protected void onResume() {
		super.onResume();
		// onActivityResult에서 돌아올때 원래 Activity의 여기가 실행됩니다.
		for (Runnable work : queue) {
			(new Thread(work)).start();
		}
		queue.clear();
	}
참고사이트 http://www.wwdiary.com/discussion/715/got-you-pesky-little-bug-/p1]]>

Related Posts