Notice
Recent Posts
Recent Comments
Link
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 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 | 29 | 30 | 31 |
Tags
- PrototypePattern
- kmp
- kotlin multiplatform
- 빌터패턴
- 코루틴
- 추상팩토리패턴
- Design Pattern
- 코틀린
- Abstract Factory
- define
- Kotlin
- 디자인패턴
- 옵저버 패턴
- builderPattern
- factory method
- 추상 팩토리
- 안드로이드 디자인시스템
- designPattern
- 코틀린멀티플랫폼
- Functional Programming
- ㅋㅁ
- 팩토리 메소드
- Coroutines
- compose
- 프로토타입 패턴
- android designsystem
- 함수형프로그래밍
- material3
- Observer Pattern
- 디자인패턴 #
Archives
- Today
- Total
오늘도 더 나은 코드를 작성하였습니까?
사용자가 정의한 LifecycleOwner 구현하기 본문
만약 LifecycleOwner를 직접 구현하려면 LifecycleRegistry 클래스를 사 용수 있다.
다음 코드 예에서와 같이 LifecycleRegistry 클래스에 이벤트를 전달해야 합니다.
public class MyActivity extends Activity implements LifecycleOwner {
private LifecycleRegistry lifecycleRegistry;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
lifecycleRegistry = new LifecycleRegistry(this);
lifecycleRegistry.markState(Lifecycle.State.CREATED); // 이벤트 전달.
}
@Override
public void onStart() {
super.onStart();
lifecycleRegistry.markState(Lifecycle.State.STARTED); // 이벤트 전달.
}
@NonNull
@Override
public Lifecycle getLifecycle() {
return lifecycleRegistry; // 이벤트 전달.
}
}
'Android Jetpack Architecture > LifeCycle' 카테고리의 다른 글
| 생명주기 인식 구성요소의 권장사항 및 예시 (0) | 2020.08.13 |
|---|---|
| Lifecycle - aware 컴포넌트 (0) | 2020.08.13 |
