androidandroid-studioandroid-databinding

What could be the reason that an app can get stuck at Binding.inflate which previously works fine?


After realizing that my app seems to be miss behaving, I did some clever debugging tactics, namely adding Log calls between my code and some cheeky debug breakpoints, I realized that my MainActivity doesn't seem to get past the binding = ActivityMainBinding.inflate(layoutInflater) line on my code. And I'm not getting any error as well. The relevant code are these lines:

Log.d(TAG, "before mainActBind")
binding = ActivityMainBinding.inflate(layoutInflater)
Log.d(TAG, "after mainActBind")
setContentView(binding.root)
Log.d(TAG, "after setContent")
setSupportActionBar(binding.appContentMain.toolbar)
Log.d(TAG, "after setSupportActionBar")

Those are the top-most lines code inside my MainActivity's onCreate, I still have super.onCreate(savedInstanceState) there as well.

And what I'm getting in Logcat looks like this:

RenderThread::setGrContext()
Checking for metadata for AppLocalesMetadataHolderService : Service not found
Access denied finding property "vendor.mali.config"
RenderThread::setGrContext()
Checking for metadata for AppLocalesMetadataHolderService : Service not found
before mainActBind
Compat change id reported: 210923482; UID 10259; state: ENABLED
Accessing hidden method Landroid/view/View;->computeFitSystemWindows(Landroid/graphics/Rect;Landroid/graphics/Rect;)Z (unsupported, reflection, allowed)
Accessing hidden method Ljava/lang/invoke/MethodHandles$Lookup;-><init>(Ljava/lang/Class;I)V (unsupported, reflection, allowed)

I'm currently running Android Studio Giraffe 2022.3.1 Patch 1. I already did Invalidate Caches, Clean, Rebuild and Make Project.

I already tried using DataBindingUtil.setContentView(this, R.layout.activity_main), but it doesn't seem to work

Here's what my activity_main.xml looks like:

<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:app="http://schemas.android.com/apk/res-auto">

    <data>

    </data>

    <androidx.drawerlayout.widget.DrawerLayout
        android:id="@+id/drawer_layout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fitsSystemWindows="true"
        tools:openDrawer="start">

        <include
            android:id="@+id/app_content_main"
            layout="@layout/app_content_main"
            android:layout_width="match_parent"
            android:layout_height="match_parent"/>

        <com.google.android.material.navigation.NavigationView
            android:id="@+id/nav_view"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_gravity="start"
            android:fitsSystemWindows="true"
            app:headerLayout="@layout/nav_header_main"
            app:menu="@menu/drawer_menu" />
    </androidx.drawerlayout.widget.DrawerLayout>
</layout>

Solution

  • Silly me, I already found the issue. Essentially, my Fragments were waiting for something that was about to get initialized in MainActivity and those waiting code blocked everything from executing including the initialization of the class that they need. So, I moved those waiting code to onStart and it fixed the issue.