implementation("androidx.core:core-ktx:1.1.0-alpha04")
implementation ("androidx.appcompat:appcompat:1.0.2")
implementation ("androidx.activity:activity-ktx:1.0.0-alpha05")
我也在看这个为什么他们有 2 个不同的 ComponentActivity 类? 我有这个库设置并希望使用OnBackPressedCallback
import android.os.Bundle
import androidx.activity.OnBackPressedCallback
import androidx.fragment.app.Fragment
open class BaseNiceFragment : Fragment(), OnBackPressedCallback {
override fun handleOnBackPressed(): Boolean {
// do some nice things here
return true
}
override fun onActivityCreated(savedInstanceState: Bundle?) {
super.onActivityCreated(savedInstanceState)
activity!!.addOnBackPressedCallback(viewLifecycleOwner, this)
}
override fun onDestroyView() {
super.onDestroyView()
activity!!.removeOnBackPressedCallback(this)
}
protected open fun handleEmptyView(isListEmpty: Boolean) {}
}
它适用于使用 Android Studio 进行调试构建,但每当我尝试执行时app:compileFullReleaseKotlin
,我都会遇到以下问题
BaseNiceFragment.kt: (_, _): Unresolved reference: OnBackPressedCallback
任何人或 Ian 都知道如何确保这包含在我的所有构建中
public interface OnBackPressedCallback {
//...
}