기본 콘텐츠로 건너뛰기

gsjava FLAG_ACTIVITY_NEW_TASK 안드로이드 오류

 android.util.AndroidRuntimeException: Calling startActivity() from outside of an Activity  context requires the FLAG_ACTIVITY_NEW_TASK flag. Is this really what you want?

startActivity를 사용할 때 위와같은 에러를 마주한다면

 

비 액티비티에서 startActivity를 호출할 때 위 에러 로그를 발견할 수 있다.


해결방안은 액티비티에서 호출을 하면 된다.


아니면,

Intent intent = ExampleActivity.newIntent(App.instance); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); App.instance.startActivity(intent);


FLAG_ACTIVITY_NEW_TASK를 추가 해주어도 된다.


Intent.FLAG_ACTIVITY_NEW_TASK

새로운 태스크 생성

: If set, this activity will become the start of a new task on this history stack.

실행하는 액티비티를 새 태스크로 생성.

affinity(동족)가 있으면 그 태스크로 들어감.

예> 앱에서 시스템 설정을 열 때,

기존에 열어둔게 없으면 -> 새로 태스크 생성. (A1) -> 태스크[A1]

기존에 열어둔게 있으면 (A1) -> 그 태스크로 들어감. (A2) -> 태스크[A1, A2]

출처: https://jhshjs.tistory.com/50 [독학하는 1인 개발자:티스토리]

댓글

이 블로그의 인기 게시물

java 특정 디렉토리에 있는 파일 목록을 읽어내기, 정렬해서 가져오기

폴더 리스트 가져오기 String path="C:\"; File dirFile=new File(path); File []fileList=dirFile.listFiles(); for(File tempFile : fileList) {   if(tempFile.isFile()) {     String tempPath=tempFile.getParent();     String tempFileName=tempFile.getName();     System.out.println("Path="+tempPath);     System.out.println("FileName="+tempFileName);     /*** Do something withd tempPath and temp FileName ^^; ***/   } } 정렬해서 가져오기 import java.io.FileFilter; import java.io.IOException; import java.util.Arrays; import java.util.Date; import org.apache.commons.io.comparator.LastModifiedFileComparator; import org.apache.commons.io.filefilter.FileFileFilter; public class LastModifiedFileComparatorTest { public static void main(String[] args) throws IOException { File directory = new File("."); // get just files, not directories File[] files = directory.listFiles((FileFilter) FileFileFilter.FILE); System.out.println("Defaul...

UltraEdit Professional Version 18.20.0.1014 라이센스 키 넣기

Step 1: unpack rar archive      Step 2: run the setup   Step 3: Use the given keygen to activate    Add the line   127.0.0.1 licensing.ultraedit.com         to your %WINDOWS%\system32\drivers\etc\hosts file                 Enter any data for license-id and password (license-id must be a         number)                 Choose Offline activation and generate corresponding activation         codes for your user codes   Step 4: Enjoy and Support Developers, Buy It, They Deserved It!