Android/Technic
startActivity 에서 Calling from outside of an Activity 에러 해결법
등촌동 꼬북이
2021. 6. 3. 11:10
startActivity를 실행할때 Calling from outise of and Activity가 뜰 때가 있다.
정확한 코드는 이렇게 Calling --- from outside of an Activity context requires the FLAG_ACTIVITY_NEW_TASK flag. Is this really what you want?
이럴 때는 Intent를 줄때 addFlags(Intent.FLAG_ACITIVITY_NEW_TASK)를 옵션으로 주면 잘 돌아간다.
예시는 아래와 같다
Intent intent = new Intent(context, cls);
context.startActivity(intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
프로젝트에 있는 코드를 긁어온거라 완전하게 어디에든 적용가능한 Pure한 형태는 아니지만..
충분히 간단한 코드이므로 필요한 곳에 적용이 가능하리라 봄(Spring 아님ㅎ;)..
참조할만한 개념이 있어 첨부한다
Task (4.1) - 새로운 task 생성 [FLAG_ACTIVITY_NEW_TASK] (tistory.com)