Intermittent issue on the lock screen (a special s...
# compose
s
Intermittent issue on the lock screen (a special surface where background/foreground states frequently change) where a Fragment is created but not rendered when using Compose.
Hello, everyone! I am currently experiencing an issue where the advertisement banner is not displaying correctly on the lock screen and would like to seek your assistance. Problem DescriptionIssue: The advertisement banner is not visible on the lock screen. • Symptoms: The
SampleAdBanner
composable is invoked, and an instance of
SampleAdFragment
is created with advertisement-related events being tracked. However, the ad is not displayed on the actual screen. (It is suspected that the visibility is set to INVISIBLE or it is not being rendered.) • Additional Information:
SampleAdFragment
works correctly in an XML environment. Implementation DetailsAd Banner Implementation: The ad banner is implemented using a Fragment and is bound through the
SampleAdBanner
composable in a Compose environment using AndroidViewBinding. • Lock Screen Characteristics: The activity frequently toggles between background and foreground states. A service detects the screen off event to create the activity in the background. • Key Composables Used: ◦ `SampleLockScreen`: Composes the entire lock screen UI. ◦ `SampleLockScreenScaffold`: A swipeable scaffold layout. ◦ `SampleAdBanner`: A composable for integrating the ad banner using a Fragment. Key Code Snippets
Copy code
@Composable
fun SampleLockScreen() {
    Box(modifier = Modifier.fillMaxSize()) {
        SampleContent() // This is visible
        SampleAdBanner() // However, this is not visible
    }
}

@Composable
fun SampleAdBanner(modifier: Modifier = Modifier) {
    val fragmentHolder = remember { mutableStateOf<SampleAdFragment?>(null) }
    val context = LocalContext.current
    val lifecycleOwner = LocalLifecycleOwner.current

    AndroidViewBinding(
        modifier = modifier,
        factory = SampleFragmentContainerBinding::inflate,
    ) {
        fragmentHolder.value = fragmentContainerView.getFragment<SampleAdFragment>()
    }
}

class SampleAdFragment : Fragment(R.layout.fragment_sample_ad) {
    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
        // can't see it, but the events here are aggregated.
    }
}
Current HypothesesModifier Configuration Issue: The size or position of the ad banner might not be set appropriately, causing it not to appear on the screen. • Compatibility Issue Between Compose and Fragment: There may be issues rendering the UI tree correctly when integrating the Fragment through
AndroidViewBinding
. Question Is it possible that the Fragment is created but the view is not rendering during the binding process? If so, is there a way to reproduce this issue?