Skip to content

4. Basic Usage

Zidd edited this page Feb 10, 2022 · 1 revision

1. Extend CoreActivity

To get DataBinding and ViewModel implementation

class HomeActivity : CoreActivity<ActivityHomeBinding, HomeViewModel>(R.layout.activity_home) {
  override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        // auto generate binding and viewModel variable
        binding.lifecycleOwner = this
        binding.viewModel = viewModel
  }
}

2. Extend NoViewModelActivity

To get DataBinding without ViewModel implementation

class HomeActivity : NoViewModelActivity<ActivityHomeBinding>(R.layout.activity_home) {
  override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        // auto generate binding variable
        binding.lifecycleOwner = this
  }
}

Activity Intent

To open activity with AndroidCore library, simple call openActivity<T>() function.

1. Open Activity without parse data

// HomeActivity.kt

openActivity<DetailActivity>()

2. Open Activity with parse data

// HomeActivity.kt

openActivity<DetailActivity> {
    putExtra("key_id", 1)
    putExtra("key_name", "awesome")
}

3. Open Activity with animation.

coming soon