Base Data Binding Activity
A base Activity class that uses DataBinding and provides common functionality for data-bound activities.
Extends ParentsBindingActivity to provide common binding functionality and permission management.
DataBinding을 사용하고 데이터 바인딩 Activity에 대한 공통 기능을 제공하는 기본 Activity 클래스입니다.
ParentsBindingActivity를 상속받아 공통 바인딩 기능과 권한 관리를 제공합니다.
Why this class exists / 이 클래스가 필요한 이유:
Android's DataBinding requires manual DataBindingUtil.setContentView() and lifecycleOwner setup for each Activity.
This class eliminates boilerplate by accepting a layout resource ID and automatically configuring DataBinding.
Enables two-way data binding with ViewModel and automatic UI updates through LiveData observables (StateFlow requires manual collection).
Android의 DataBinding은 각 Activity마다 수동으로 DataBindingUtil.setContentView() 및 lifecycleOwner 설정이 필요합니다.
이 클래스는 레이아웃 리소스 ID를 받아 자동으로 DataBinding을 구성하여 보일러플레이트를 제거합니다.
ViewModel과의 양방향 데이터 바인딩 및 LiveData 옵저버블을 통한 자동 UI 업데이트를 가능하게 합니다 (StateFlow는 수동 수집 필요).
Design decisions / 설계 결정 이유:
Uses constructor parameter for layout resource ID to enable simple single-line class declaration.
Automatically sets lifecycleOwner in createBinding() to enable LiveData observation in XML layouts.
Implements final createBinding() to prevent subclasses from breaking the DataBinding initialization contract.
Inherits event collection infrastructure from ParentsBindingActivity for consistent ViewModel integration.
간단한 한 줄 클래스 선언을 위해 생성자 파라미터로 레이아웃 리소스 ID를 사용합니다.
XML 레이아웃에서 LiveData 관찰을 가능하게 하기 위해 createBinding()에서 자동으로 lifecycleOwner를 설정합니다.
final createBinding()을 구현하여 하위 클래스가 DataBinding 초기화 계약을 깨는 것을 방지합니다.
일관된 ViewModel 통합을 위해 ParentsBindingActivity로부터 이벤트 수집 인프라를 상속받습니다.
Usage / 사용법:
Extend this class with your Activity and pass the layout resource ID.
Bind your ViewModel to the binding object in onCreate(binding, savedInstanceState) (binding is passed as parameter).
Use XML data binding expressions to bind views to ViewModel properties.
Override onEventVmCollect(binding:BINDING) to collect ViewModel events with repeatOnLifecycle().
Access binding in other methods via getBinding() if needed.
Activity에서 이 클래스를 상속받고 레이아웃 리소스 ID를 전달하세요.
onCreate(binding, savedInstanceState)에서 ViewModel을 binding 객체에 바인딩하세요 (binding은 파라미터로 전달됩니다).
XML 데이터 바인딩 표현식을 사용하여 뷰를 ViewModel 프로퍼티에 바인딩하세요.
repeatOnLifecycle()로 ViewModel 이벤트를 수집하려면 onEventVmCollect(binding:BINDING)를 오버라이드하세요.
필요한 경우 다른 메서드에서 getBinding()을 통해 바인딩에 접근하세요.
Usage example:
class MainActivity : BaseDataBindingActivity<ActivityMainBinding>(R.layout.activity_main) {
private val viewModel: MainViewModel by lazy { getViewModel() }
override fun onCreate(binding: ActivityMainBinding, savedInstanceState: Bundle?) {
binding.viewModel = viewModel
setupViews()
}
override fun onEventVmCollect(binding:BINDING) {
lifecycleScope.launch {
repeatOnLifecycle(Lifecycle.State.STARTED) {
viewModel.events.collect { event -> handleEvent(event) }
}
}
}
}Parameters
The type of the DataBinding class.
DataBinding 클래스의 타입.
The layout resource ID for the activity.
Activity의 레이아웃 리소스 ID.
See also
For the parent class providing binding lifecycle.
바인딩 생명주기를 제공하는 부모 클래스는 ParentsBindingActivity를 참조하세요.
For simple layout-based Activity without DataBinding.
DataBinding 없이 간단한 레이아웃 기반 Activity는 BaseActivity를 참조하세요.
For ViewBinding-enabled Activity.
ViewBinding을 사용하는 Activity는 BaseViewBindingActivity를 참조하세요.
Properties
Functions
Returns and clears denied results that lost their callbacks after process restore.
Call this in onCreate to handle results from requests that were interrupted by process kill.
프로세스 복원 후 콜백을 잃은 거부 결과를 반환하고 비웁니다.
프로세스 킬로 중단된 요청의 결과를 처리하려면 onCreate에서 호출하세요.
Gets a color using ContextCompat for backward compatibility.
역호환성을 위해 ContextCompat을 사용하여 색상을 가져옵니다.
Gets dimension pixel offset for the given dimension resource.
주어진 dimension 리소스의 픽셀 오프셋을 가져옵니다.
Gets dimension pixel size for the given dimension resource.
주어진 dimension 리소스의 픽셀 크기를 가져옵니다.
Gets a drawable using ContextCompat for backward compatibility.
역호환성을 위해 ContextCompat을 사용하여 drawable을 가져옵니다.
Safely gets a drawable, returning null if resource is not found or invalid.
리소스를 찾을 수 없거나 유효하지 않은 경우 null을 반환하여 안전하게 drawable을 가져옵니다.
Gets integer value from resources.
리소스에서 정수 값을 가져옵니다.
Safely gets a string, returning empty string if resource is not found or invalid.
리소스를 찾을 수 없거나 유효하지 않은 경우 빈 문자열을 반환하여 안전하게 문자열을 가져옵니다.
Checks if the context is destroyed or finishing.
컨텍스트가 파괴되었거나 종료 중인지 확인합니다.
Called when the binding is initialized in onCreate().
Implement setup logic that requires binding here.
onCreate에서 바인딩이 초기화된 후 호출됩니다.
바인딩이 필요한 초기화 로직을 여기서 수행하세요.
Collect ViewModel events here.
Use repeatOnLifecycle(Lifecycle.State.STARTED) to avoid duplicate collectors.
ViewModel 이벤트를 수집하는 훅입니다.
중복 수집 방지를 위해 repeatOnLifecycle(Lifecycle.State.STARTED)를 사용하세요.
Requests runtime permissions and returns denied results via callback.
Delegates to PermissionRequester for actual permission handling.
런타임 권한을 요청하고 콜백을 통해 거부 결과를 반환합니다.
실제 권한 처리는 PermissionRequester에 위임합니다.
Creates a long duration Toast without showing it.
Allows further customization before displaying.
표시하지 않고 긴 시간 Toast를 생성합니다.
표시하기 전에 추가 커스터마이징이 가능합니다.
Creates a short duration Toast without showing it.
Allows further customization before displaying.
표시하지 않고 짧은 시간 Toast를 생성합니다.
표시하기 전에 추가 커스터마이징이 가능합니다.
Creates and shows a long duration Toast message.
긴 시간 Toast 메시지를 생성하고 표시합니다.
Creates and shows a short duration Toast message.
짧은 시간 Toast 메시지를 생성하고 표시합니다.