[블러그 "참 쉽습니까?"] 부팅시 서비스 호출 굿

http://blog.naver.com/oh4zzang/40112687127


[안드로이드펍 ] QNA

http://www.androidpub.com/8739

Posted by bestrok
,


 

 //...  생략 ...



int returnCode = 1;

Intent intent = new Intent();
intent.setAction( Intent.ACTION_GET_CONTENT );
intent.setType( "image/*" );  //video/* 은 비데오 파일
this.startActivityForResult( intent, this.returnCode );


//onActivityResult 로 콜백처리 할 것.


'IT > Android' 카테고리의 다른 글

RUN Thread 사용  (0) 2011.10.27
ScrollView 안에 이미지 적용시 중복된 여백이 생기는 경우.  (0) 2011.10.27
media scanning  (0) 2011.10.27
Map API 등록하기  (0) 2011.10.27
INTENT Activity 호출유형  (0) 2011.10.27
Posted by bestrok
,

int FLAG_ACTIVITY_BROUGHT_TO_FRONT This flag is not normally set by application code, but set for you by the system as described in the launchMode documentation for the singleTask mode. 
int FLAG_ACTIVITY_CLEAR_TASK

If set in an Intent passed to Context.startActivity(), this flag will cause any existing task that would be associated with the activity to be cleared before the activity is started.


int FLAG_ACTIVITY_CLEAR_TOP

If set, and the activity being launched is already running in the current task, then instead of launching a new instance of that activity, all of the other activities on top of it will be closed and this Intent will be delivered to the (now on top) old activity as a new Intent.

액티비티를 새 인스턴스에 태우지 않고, 현재 테스크에 이미 실행중인 액티비티에 실행한다.  

그 실행된 액티비티 위에 있던 모든 액티비티는 닫히며, 그 인텐트는 새로운 액티비티 처럼 전달될 것이다.

int FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET If set, this marks a point in the task's activity stack that should be cleared when the task is reset.
int FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS If set, the new activity is not kept in the list of recently launched activities.
int FLAG_ACTIVITY_FORWARD_RESULT If set and this intent is being used to launch a new activity from an existing one, then the reply target of the existing activity will be transfered to the new activity.
int FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY This flag is not normally set by application code, but set for you by the system if this activity is being launched from history (longpress home key).
int FLAG_ACTIVITY_MULTIPLE_TASK Do not use this flag unless you are implementing your own top-level application launcher.
int FLAG_ACTIVITY_NEW_TASK

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

새 액티비티가 테스크 히스토리 스택에 쌓인다. (디폴트 아닌가?)

int FLAG_ACTIVITY_NO_ANIMATION If set in an Intent passed to Context.startActivity(), this flag will prevent the system from applying an activity transition animation to go to the next activity state.
int FLAG_ACTIVITY_NO_HISTORY

If set, the new activity is not kept in the history stack.

새로운 실행된 액티비티가 히스토리 스택에 쌓이지 않는다.

int FLAG_ACTIVITY_NO_USER_ACTION If set, this flag will prevent the normal onUserLeaveHint() callback from occurring on the current frontmost activity before it is paused as the newly-started activity is brought to the front.
int FLAG_ACTIVITY_PREVIOUS_IS_TOP If set and this intent is being used to launch a new activity from an existing one, the current activity will not be counted as the top activity for deciding whether the new intent should be delivered to the top instead of starting a new one.
int FLAG_ACTIVITY_REORDER_TO_FRONT

If set in an Intent passed to Context.startActivity(), this flag will cause the launched activity to be brought to the front of its task's history stack if it is already running.

Context.startActivity() 로 전될된 인텐트일 경우, 이 플래그는 테스크 중에 이미 실행중인 액티비티를 히스토리스택의 제일 위로 올려준다. (새 인텐트가 아니므로 실행시킨 액티비티기 지존에 없다는 실행되지 않는다. 단지 자리만 바꾸는 역할을 한다.)


int FLAG_ACTIVITY_RESET_TASK_IF_NEEDED

If set, and this activity is either being started in a new task or bringing to the top an existing task, then it will be launched as the front door of the task.

이렇게 실행된 액티비티는 새태스크로 시작되거나 가져오거나 이미 존재하는 태스크에 속할 것이다. 그것은 태스크가 처음 실행된 것처럼 실행될 것이다.

int FLAG_ACTIVITY_SINGLE_TOP

If set, the activity will not be launched if it is already running at the top of the history stack.

이 액티비티는 히스토리 스택의 최상위에서 이미 존재할 경우, 실행하지 않을 것이다. (기존에 있는 액티비티를 최상위 스택으로 그대로 가져온다.)

int FLAG_ACTIVITY_TASK_ON_HOME

If set in an Intent passed to Context.startActivity(), this flag will cause a newly launching task to be placed on top of the current home activity task (if there is one). 

That is, pressing back from the task will always return the user to home even if that was not the last activity they saw. This can only be used in conjunction with FLAG_ACTIVITY_NEW_TASK.

이 플래그는 현재 원본 액티비티의 태스크 최상위에 위치로 새롭게 태스크를 시작하도록 한다. (액티비티가 1개일 경우) ?????????

back 버튼을 누르면 항상 Home으로 간다. 심지어 마지막 액티비티가 아닌 것으로 보일 지라도 말이다. 이 플래그는 FLAG_ACTIVITY_NEW_TASK와 함께 사용할 수 있다.

int FLAG_DEBUG_LOG_RESOLUTION A flag you can enable for debugging: when set, log messages will be printed during the resolution of this intent to show you what has been found to create the final resolved list.
int FLAG_FROM_BACKGROUND

Can be set by the caller to indicate that this Intent is coming from a background operation, not from direct user interaction.


int FLAG_GRANT_READ_URI_PERMISSION If set, the recipient of this Intent will be granted permission to perform read operations on the Uri in the Intent's data.
int FLAG_GRANT_WRITE_URI_PERMISSION If set, the recipient of this Intent will be granted permission to perform write operations on the Uri in the Intent's data.
int FLAG_RECEIVER_REGISTERED_ONLY If set, when sending a broadcast only registered receivers will be called -- no BroadcastReceiver components will be launched.
int FLAG_RECEIVER_REPLACE_PENDING If set, when sending a broadcast the new broadcast will replace any existing pending broadcast that matches it.


'IT > Android' 카테고리의 다른 글

media scanning  (0) 2011.10.27
Map API 등록하기  (0) 2011.10.27
EditText 커서위치 설정  (0) 2011.10.27
diplay.getOrientation  (0) 2011.10.27
Activity Recycle  (0) 2011.10.27
Posted by bestrok
,

Activity Recycle

IT/Android 2011. 10. 27. 14:43

'IT > Android' 카테고리의 다른 글

EditText 커서위치 설정  (0) 2011.10.27
diplay.getOrientation  (0) 2011.10.27
Intent FLAG (by 투덜이님의 노트)  (0) 2011.10.27
Error generating final archive: Debug certificate expired  (0) 2011.10.27
Android Development Terms  (0) 2011.10.27
Posted by bestrok
,

일반적인 경우, 안드로이드 용 어플리케이션을 작성하게 되면 여러가지 Activity 들을 생성하게 됩니다. 이때, 가장 골치가 아픈 일 중 하나는 바로 Activity 와 Activity 간의 Flow 를 설계하고 이를 적절하게 구현하는 일입니다. (특히 안드로이드를 사용해보지도 않은 UX 팀과 함께 일하게 되는 경우라면 더욱 그러합니다...)

 
 기본적으로 안드로이드 플랫폼 상에서 Activity 는 또 다른 Activity 를 시작할 수 있고, 각각의 Activity 는 차곡 차곡 Task 라고 불리우는 Activity Stack 에 쌓이게 됩니다. 사용자는 일반적으로 Back 버튼을 이용해서 현재 화면상에 보이는 Activity 를 종료 시키고, 바로 직전에 사용된 Activity 로 돌아갈 수 있습니다. 안드로이드 펍의 회색님의 말을 빌리자면, 인터넷 브라우저를 통해 웹페이지를 검색하는 것과 유사한 방식입니다. 
 
 하 지만 이러한 방법만으로는 효과적인 UX Flow 를 구축하는데 어려움이있습니다. 다행히, 구글에서는 Activity 를 호출할 때 사용되는 Intent 에 적절한 플래그 값을 설정해서 Activity Stack 을 제어할 수 있는 방법을 제공해 줍니다. 이 플래그들은  FLAG_ACTIVITY 라는 접두어를 갖고 있는데, 종류가 다양해 헷갈리는 수도 있는데, 개인적으로 제가 가장 요긴하게 사용하고 있는 FLAG_ACTIVITY 네 가지를 소개해 봅니다. 
 

 먼저 FLAG_ACTIVITY_SINGLE_TOP 입니다. 우선 간단하게 그림으로 표현해 보았습니다. A 와 B  두 가지 Activity 가 있는 데, A 라는 Activity 는 B 를 B 라는 Activity 는 다시 자기 자신인 B 를 호출 하는 경우라고 가정해 보겠습니다.1.jpg

호 출하는 Activity B 가 이미 Task 의 가장 앞에 위치하는 경우, 또 하나의 B 를 생성하는 대신, 기존에 존재하는 B Activity 가 재활용됩니다. 이 때 B 가 재활용된다는 것을 개발자가 알아채고 새롭게 전달되는 Intent 를 사용할 수 있도록 B Activity 의 onPause() / onNewIntent() / onResume() 가 순차적으로 호출됩니다. 별 생각없이 동일한 Activity 를 여러번 생성하는 것은 메모리 사용량과 Activity 시작 속도 양쪽 모두에 악영향을 끼칠 수 있습니다. (특히 이미지가 덕지덕지 붙어 있는 Activity 라면). 이런 경우 FLAG_ACTIVITY_SINGLE_TOP 를 적절하게 활용하면 제법 큰 효과를 볼 수 있습니다.
 
 두 번째는, FLAG_ACTIVITY_NO_HISTORY 플래그입니다. 우 선 간단하게 그림으로 표현해 보았습니다. A 와 B  두 가지 Activity 가 있는 데, A 라는 Activity 는 B 를 B 라는 Activity 는 A 를 호출한 후 에 (A->B->A) 사용자가 Back 키를 누르는 경우를 가정해 보겠습니다.

 2.jpg

 

 

말 그대로, FLAG_ACTIVITY_NO_HISTORY 로 설정된 Intent 로 시작된 Activity B 는 Task 에 그 흔적을 남기지 않게 됩니다. B 에서 또다른 A 를 시작한 후, Back 을 누르면 일반적인 경우 이전에 실행되었던 B 가 나타나지만, NO_HISTORY 를 사용하는 경우 맨 처음에 실행 되었던 A 가 화면에 표시됩니다. 몇 가지 주의할 점이 있습니다. 우선 NO_HISTORY 를 사용하게 되면 Task 에 해당 Intent 의 정보가 기록되지 않기 때문에, A->B 인 상황 (그림에서 두 번째 단계...) 에서 홈키등을 눌러 다른 Task 로 전환된 후, 다시 본 Task 로 돌아오게 되면, A Activity 가 화면에 표시됩니다. 또한, B Activity 의 onDestroy() 가 호출되는 시점이 조금 애매합니다.일반적인 예상과는 달리, B 에서 또다른 A Activity 를 호출하는 세 번째 단계에서는 onStop 까지만 호출되고, 이 후에 새롭게 호출된 A Activity 가 사라지는 순간 (네 번째 단계) 에서야 onDestroy() 가 호출 됩니다.
 
 FLAG_ACTIVITY_NO_HISTORY 는 여러가지로 쓸모가 있는데, 특히 특정한 이벤트에 대한 알람등을 위해 다이얼로그 형태로 화면에 표시되는 Activity 들에 적용하기에 편리합니다. (대게의 경우 팝업은 해당 시점에 한번만 보여주면 되니까.)
 
 다음으로 굉장히 유용한 플래그 두 가지를 동시에 설명해보고자 합니다. FLAG_ACTIVITY_REORDER_TO_FRONT 와 FLAG_ACTIVITY_CLEAR_TOP 플래그입니다. 우선 간략하게 그림으로 살펴 보겠습니다. A Activity 에서 B Activity 를 그리고 B 에서 A 를 호출하는 상황을 가정해보았습니다. (A->B->A)

3.jpg

 

 

FLAG_ACTIVITY_REORDER_TO_FRONT 는 매우 특이하게도 Task 의 순서 자체를 뒤바꿔 줍니다. 이 플래그를 사용하면, 런치하고자 하는 Activity 가 이미 Task 상에 존재하는 경우 해당 Activity 를 새롭게 생성하는 대신, 아래쪽에 위치한 Activity 의 순서를 Task 의 가장 위로 끌어올려줍니다. 따라서 A->B->A 의 순서로 Activity 호출이 일어날때, 새로운 A 가 생성되는 대신 아래쪽에 위치한 A 가 위로 올라와 최종적으로 B->A 의 형태로 Task 가 구성되게 됩니다. 어떤 Activity 에서 특정 Activity 로 점프하는 형식의 Flow 를 구성해야하는 경우 요긴하게 사용될 수도 있지만, Task 의 순서를 뒤섞는 다는 점에서 사용에 주의를 기울일 필요가 있습니다.  (별 생각없이 남발하게 되면 Back 키가를 누를 때 엉뚱한 Activity 가 표시되어 사용자들이 굉장히 혼란스러워 하는 경우가 있습니다.) 
 
 마지막으로 소개해 드릴 플래그는 바로 FLAG_ACTIVITY_CLEAR_TOP 입니다. 제가 개인적으로 가장 사랑스럽게 생각하는 녀석입니다. 이 플래그가 사용되는 경우  
런 치하고자 하는 Activity 가 이미 Task 상에 존재하는 경우, 해당 Activity 위에 존재하는 다른 Activity 를 모두 종료시켜 줍니다. 따라서 A->B->A 로 호출이 일어나는 경우, B Activity 가 종료 되고, A Activity 만 Task 에 남게 됩니다. (A->B->C->A 인 경우에도 마찬가지로 B와 C 가 종료되고 A 만 남게 됩니다.)
  이 Flag 는 특정 어플리케이션의 대쉬보드 (혹은 홈) Activity 를 호출할 때 굉장히 유용하게 사용될 수 있습니다. 즉 하나의 어플리케이션이 하나 혹은 두 가지의 주요한 Activity 와 그 외 특정 값을 선택하는등 단순한 일을 수행하기 위한 여러 개의 Sub-Activity 로 구성되어 있다면, 주요 Activity 를 호출하는데 이 Flag 를 사용함으로서 어플리케이션의 홈버튼등을 손쉽게 구현할 수 있습니다. 또 이 Flag 는 FLAG_ACTIVITY_REORDER_TO_FRONT 와는 달린 Task 의 순서를 뒤섞지 않음으로 사용자에게도 큰 혼란을 주지 않습니다. (사용을 적극 권장합니다.)
 한 가지 주의해야할 점은 A->B->A 형태로 Activity 를 호출 하고자 할 때, 단순히 FLAG_ACTIVITY_CLEAR_TOP 만을 사용하게 되면, 기존에 생성되었던 A Activity 가 종료된 후 (onDestroy() 가 호출됨) 새롭게 A 가 생성 (onCreate()) 됩니다. 만일 기존에 사용된 A Activity 가 계속 사용되기를 원한다면, SINGLE_TOP 플래그와 함께 사용해야 합니다.
FLAG_ACTIVITY_SINGLE_TOP
Activity가 스택의 맨 위에 존재 하는 경우에 기존 Activity를 재활용 한다.
 
(Activity호출순서) 0->1->2->3   이렇게 스택이 쌓인 경우(스택의 맨 위는 3)   
  1. intent = new Intent(this, Activity3.class);  
  2. intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);  
  3. startActivity(intent);  
0->1->2->3 그래도 유지 된다. 대신 Activity3는 onPause()->onNewIntent() -> onResume() 호출된다.
3번 액티비티가 존재하지 않거나 스택의 맨 위가 아닌 경우 그냥 스택에 쌓이게 되며 onNewIntent() 도 호출된다.
 
 
FLAG_ACTIVITY_NO_HISTORY
해당 플래그를 주고 액티비티를 호출하면 호출된 액티비티는 스택에 남지 않는다.
0->1->2->3  호출할때 Activity2 에서 Activity 3를 호출할때 
  1. intent = new Intent(this, ActivityTest3.class);  
  2. intent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);  
  3. startActivity(intent);  
하면 스택에는 0->1->3 만 남게 된다.  하지만 Activity 2의 Destory()의 시점은 Activity 3이 종료 된 이후에 호출된다라는것을 주의한다.
 
 
FLAG_ACTIVITY_REORDER_TO_FRONT
스택의 순서를 변경해 준다.
0->1->2->3 일때 Activity 3에서 Activity 1을 호출 할때 이 플래그를 설정하면 
0->2->3->1 로 변경된다. (안드로이드 문서에서 FLAG_ACTIVITY_CLEAR_TOP플래그를 무시한다고 되어 있다.)
 
 
FLAG_ACTIVITY_CLEAR_TOP
스택에 기존에 사용하던 Activity가 있다면 그 위의 스택을 전부 제거해 주고 호출한다.
0->1->2->3 일때 Activity 3에서 Activity 1을 호출할때 이 플래그를 설정하면
0->1 만 남게 된다. (2, 3은 제거)  이때 Activity 1은 onDestory() -> onCreate()가 호출된다. 삭제하고 다시 만들게 된다.
 
그래서~~ FLAG_ACTIVITY_SINGLE_TOP와 같이 써준다. 그러면 onNewIntent()-> onResume() 가 호출된다.
만약 스택에 없다면~~ 당연히 아무것도 지우지 못하고 맨 위에 올라가게 된다.
 
  1. intent = new Intent(this, ActivityTest1.class);  
  2. intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP|Intent.FLAG_ACTIVITY_SINGLE_TOP);  
  3. startActivity(intent); 



[출처] 투덜이님의 노트 : http://chihun80.springnote.com/pages/6423199
Posted by bestrok
,

AndroidManifest.xml 에


해당하는 액티비티에만 다음을 추가.
android:configChanges="keyboardHidden|orientation"

모든 액티비티가 onCreate 타지 않으려면 
모든 액티비티에 추가해야 함.
Posted by bestrok
,