[안드로이드] FragmentActivity란 무엇인가?

프로그래밍/Android 관련2017. 12. 15. 21:46

안녕하세요. 개발자 드리머즈입니다.


Activity와 Fragment 개념이 헷갈리는데.. FragmentActivity라는 것에 대해서 듣게되면..

더욱 헷갈리게 됩니다.


그래서 stackoverflow에서 FragmentActivity가 무엇인지 찾아봤습니다.

좋은 글이 있네요.


https://stackoverflow.com/questions/31297246/activity-appcompatactivity-fragmentactivity-and-actionbaractivity-when-to-us

 

I thought Activity was deprecated

No.

So for API Level 22 (with a minimum support for API Level 15 or 16), what exactly should I use both to host the components, and for the components themselves? Are there uses for all of these, or should I be using one or two almost exclusively?

Activity is the baseline. Every activity inherits from Activity, directly or indirectly.

FragmentActivity is for use with the backport of fragments found in the support-v4 and support-v13 libraries. The native implementation of fragments was added in API Level 11, which is lower than your proposed minSdkVersion values. The only reason why you would need to consider FragmentActivity specifically is if you want to use nested fragments (a fragment holding another fragment), as that was not supported in native fragments until API Level 17.

AppCompatActivity is from the appcompat-v7 library. Principally, this offers a backport of the action bar. Since the native action bar was added in API Level 11, you do not need AppCompatActivity for that. However, current versions of appcompat-v7 also add a limited backport of the Material Design aesthetic, in terms of the action bar and various widgets. There are pros and cons of using appcompat-v7, well beyond the scope of this specific Stack Overflow answer.

ActionBarActivity is the old name of the base activity from appcompat-v7. For various reasons, they wanted to change the name. Unless some third-party library you are using insists upon an ActionBarActivity, you should prefer AppCompatActivity over ActionBarActivity.

So, given your minSdkVersion in the 15-16 range:

  • If you want the backported Material Design look, use AppCompatActivity

  • If not, but you want nested fragments, use FragmentActivity

  • If not, use Activity

Just adding from comment as note : AppCompatActivity extends FragementActivity, so anyone needs to use features of FragmentActivity, then can use AppCompatActivity.


대충 번역을 해보면..

Activity는 더이상 지원되지 않는다고 생각했습니다.

아닙니다.

(API 레벨 15, 16을 최소한으로 지원하는)API 레벨 22에서, 컴포넌트를 관리하기 위해, 그리고 컴포넌트 자체를 위해 정확하게 어떤 것을 사용해야 하나요? 이 모든 것에 대한 쓰임이 있는 것인지 아니면, 거의 독점적으로 하나 또는 두 개를 사용해야 하나요?

Activity 는 베이스라인입니다. 모든 액티비티는 직접적으로든 간접적으로든 Activity를 상속받습니다.


FragmentActivity 는 support-v4 와 support-v13 라이브러리에서 발견되는 fragment를 지원하기 위해 사용됩니다. fragment는 API 레벨 11에서 처음으로 도입이 되었는데, 이는 당신이 생각한 minSdkVersion 값보다 더 적습니다. 당신이 FragmentActivity를 고려해야 하는 유일한 경우는 만약 당신이 중첩된 fragment를 사용하고 싶어할 때입니다. 왜냐하면 중첩된 fragment는 API 레벨 17까지 네이티브 fragment에서 지원하지 않았기 때문입니다.


AppCompatActivity 는 appcompat-v7 라이브러리에 있습니다. 주로, 이는 액션 바의 호환성을 제공합니다. 네이티브 액션 바는 API 레벨 11에 추가됐기에, 당신은 액션 바를 사용하기 위해 AppCompatActivity가 필요하지 않습니다. 그러나, 현재 appcompat-v7 버전은 또한 제한된 (액션 바와 다양한 위젯들에 대한) 머티리얼 디자인 미학의 호환성을 추가했습니다. appcompat-v7를 사용하는 것에 대한 장/단점이 있으나, 이 스택 오버플로우 답변의 범위를 훨씬 넘습니다.


ActionBarActivity 는 appcompat-v7의 베이스 액티비티의 예전 이름입니다. 다양한 이유로 구글은 이름을 바꾸기를 원했습니다. 어떤 외부 업체의 라이브러리가 ActionBarActivity 사용하기를 고집부리지 않는 한, 당신은 ActionBarActivity 대신에 AppCompatActivity 를 사용해야 합니다.


따라서, 당신의 minSdkVersion 가 15-16 값의 범위로 주어졌을 때,

  • 머티리얼 디자인 외형의 호환성을 지원하고 싶으면, AppCompatActivity를 사용하세요

  • 그렇지 않고, 중첩된 fragment를 사용하고자 한다면, FragmentActivity를 사용하세요

  • 그것도 아니면, Activity를 사용하세요.

알림 : AppCompatActivity는 FragementActivity를 상속받기에, FragementActivity의 피쳐를 사용하고자 하는 사람은 AppCompatActivity를 사용하면 됩니다.




작성자

Posted by 드리머즈

관련 글

댓글 영역