티스토리 뷰

Programming/Android

[Android] Fragment

RosyPark 2020. 11. 28. 10:07

 

Fragment

- Activity는 화면을 표현하기 위한 기본 단위, 하지만 많이 구성하다 보면 화면이 너무 복잡하거나 코드의 양이 너무 많아짐

- 프레그먼트? 각각의 화면을 분할해서 독립적인 코드로 구성할 수 있도록 도와주는 것, 즉 sub-activity 

- 프레그먼트를 사용하면 하나의 액티비티로 조건에 따라 서로 다른 화면 구성을 만들 수 있음 

 

 

https://www.quora.com/What-is-the-fragment-life-cycle-in-Android

 

Fragment Start(생성주기 메소드) 

  • onAttach():- The fragment instance is associated with an activity instance.The fragment and the activity is not fully initialized. Typically you get in this method a reference to the activity which uses the fragment for further initialization work.
  • onCreate():- The system calls this method when creating the fragment. You should initialize essential components of the fragment that you want to retain when the fragment is paused or stopped, then resumed.
  • onCreateView():- The system calls this callback when it's time for the fragment to draw its user interface for the first time. To draw a UI for your fragment, you must return a View component from this method that is the root of your fragment's layout. You can return null if the fragment does not provide a UI.
  • onActivityCreated():- The onActivityCreated() is called after the onCreateView() method when the host activity is created. Activity and fragment instance have been created as well as the view hierarchy of the activity. At this point, view can be accessed with the findViewById() method. example. In this method you can instantiate objects which require a Context object
  • onStart():- The onStart() method is called once the fragment gets visible.
  • onResume():- Fragment becomes active.

 

Fragment End(소멸주기 메소드) 

  • onPause():- The system calls this method as the first indication that the user is leaving the fragment. This is usually where you should commit any changes that should be persisted beyond the current user session.
  • onStop():- Fragment going to be stopped by calling onStop()
  • onDestroyView():- Fragment view will destroy after call this method
  • onDestroy():- onDestroy() called to do final clean up of the fragment's state but Not guaranteed to be called by the Android platform.

 

 

<출처> 

1. https://www.quora.com/What-is-the-fragment-life-cycle-in-Android

2. 

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

[Android] Activity  (0) 2020.11.28
[Android] Layout  (0) 2020.11.28
[Android] View  (0) 2020.11.28
[Android] View Container  (0) 2020.11.26
[Android/Jetpack] Room DB 저장과 비동기처리  (0) 2020.09.19
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
TAG more
«   2025/02   »
1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28
글 보관함