如何在一个 activity 中同时扩展 FragmentActivity 和 WearableActivity?

How to extend both FragmentActivity and WearableActivity in one activity?

如何在 activity 中同时扩展 FragmentActivityWearableActivity

我有一个手表应用程序,我想使用常亮环境模式,但它是 fragmentActivity

在朋友的帮助下,只是没有使用片段的v4支持库。使用导入 android.app.Fragment;而不是导入 android.support.v4.app.Fragment;

您应该实施 AmbientMode.AmbientCallbackProvider 而不是使用 WearableActivity

这是首选方法,它仍然为您提供 onEnterAmbient()onAmbientUpdate()onExitAmbient(),但您可以使用 FragmentActivity.

Official docs call out the details (and example code).

根据 documentation:

The 27.1.0 version of the Android Support Library enables a new way to support ambient mode that uses the AmbientModeSupport class rather than the WearableActivity class. You can decide whether you want to use the new, preferred way to support ambient mode or instead extend the WearableActivity class.

因此,要使用新的androidx.fragment.app.FragmentFragmentManager,您必须使用新的AmbientModeSupportclass。否则,您可以继续使用 WearableActivity.