'"Failed to find cgroup for tid XXX", application crashes with background thread

I'm trying to build a custom launcher for Android, and I'm following this guide to have a clue of what I'm doing. Till the first part everything's ok, it works and loads every application, but when it comes the moment to implement the faster loading with a background thread here comes the problems. When I open the drawer, it loads few or totally no app, and looking at the output I can read a ton of ""Failed to find cgroup for tid XXX", I imagine one for every app it didn't manage to load. I can do it some times, untile the time it just crashes. The full error is:

E/SchedPolicy: Failed to find cgroup for tid 574
E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.bernard.aalauncher, PID: 574
    java.lang.IndexOutOfBoundsException: Inconsistency detected. Invalid item position 4(offset:4).state:263 androidx.recyclerview.widget.RecyclerView{3254fe9 VFED..... ......ID 0,0-1768,2120 #7f080050 app:id/appsList}, adapter:com.bernard.aalauncher.RAdapter@7476dd2, layout:androidx.recyclerview.widget.GridLayoutManager@f4beea3, context:com.bernard.aalauncher.AppsDrawer@b40bf7d
        at androidx.recyclerview.widget.RecyclerView$Recycler.tryGetViewHolderForPositionByDeadline(RecyclerView.java:6183)
        at androidx.recyclerview.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:6118)
        at androidx.recyclerview.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:6114)
        at androidx.recyclerview.widget.LinearLayoutManager$LayoutState.next(LinearLayoutManager.java:2303)
        at androidx.recyclerview.widget.GridLayoutManager.layoutChunk(GridLayoutManager.java:561)
        at androidx.recyclerview.widget.LinearLayoutManager.fill(LinearLayoutManager.java:1587)
        at androidx.recyclerview.widget.LinearLayoutManager.onLayoutChildren(LinearLayoutManager.java:665)
        at androidx.recyclerview.widget.GridLayoutManager.onLayoutChildren(GridLayoutManager.java:170)
        at androidx.recyclerview.widget.RecyclerView.dispatchLayoutStep2(RecyclerView.java:4134)
        at androidx.recyclerview.widget.RecyclerView.dispatchLayout(RecyclerView.java:3851)
        at androidx.recyclerview.widget.RecyclerView.onLayout(RecyclerView.java:4404)
        at android.view.View.layout(View.java:24456)
        at android.view.ViewGroup.layout(ViewGroup.java:7412)
        at androidx.constraintlayout.widget.ConstraintLayout.onLayout(ConstraintLayout.java:1873)
        at android.view.View.layout(View.java:24456)
        at android.view.ViewGroup.layout(ViewGroup.java:7412)
        at android.widget.FrameLayout.layoutChildren(FrameLayout.java:374)
        at android.widget.FrameLayout.onLayout(FrameLayout.java:312)
        at android.view.View.layout(View.java:24456)
        at android.view.ViewGroup.layout(ViewGroup.java:7412)
        at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1829)
        at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1673)
        at android.widget.LinearLayout.onLayout(LinearLayout.java:1582)
        at android.view.View.layout(View.java:24456)
        at android.view.ViewGroup.layout(ViewGroup.java:7412)
        at android.widget.FrameLayout.layoutChildren(FrameLayout.java:374)
        at android.widget.FrameLayout.onLayout(FrameLayout.java:312)
        at android.view.View.layout(View.java:24456)
        at android.view.ViewGroup.layout(ViewGroup.java:7412)
        at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1829)
        at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1673)
        at android.widget.LinearLayout.onLayout(LinearLayout.java:1582)
        at android.view.View.layout(View.java:24456)
        at android.view.ViewGroup.layout(ViewGroup.java:7412)
        at android.widget.FrameLayout.layoutChildren(FrameLayout.java:374)
        at android.widget.FrameLayout.onLayout(FrameLayout.java:312)
        at com.android.internal.policy.DecorView.onLayout(DecorView.java:1330)
        at android.view.View.layout(View.java:24456)
        at android.view.ViewGroup.layout(ViewGroup.java:7412)
        at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:4583)
        at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:4005)
        at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:2893)
        at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:10445)
        at android.view.Choreographer$CallbackRecord.run(Choreographer.java:1108)
        at android.view.Choreographer.doCallbacks(Choreographer.java:866)
        at android.view.Choreographer.doFrame(Choreographer.java:797)
        at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:1092)
        at android.os.Handler.handleCallback(Handler.java:938)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at android.os.Looper.loopOnce(Looper.java:226)
        at android.os.Looper.loop(Looper.java:313)
        at android.app.ActivityThread.main(ActivityThread.java:8663)
E/AndroidRuntime:     at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:567)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1135)

Here's the repository for my code, it's just a test, so you'll find just the files mentioned in that tutorial, I hope someone of you will have patience to take a look and help me to sort it out. Last thing, I'm testing it on my Samsung Z Fold 3 with android 12, which explains the permission to query all packages in Manifest file.



Solution 1:[1]

The probem is not connected to the "Failed to find cgroup for tid" messages. They are internal. Did you try to wrap the rAdapter.notifyItemInserted(rAdapter.getItemCount()-1); call inside a runOnUiThread()? Try like this:


        @Override
        protected void onPostExecute(String result) {
            super.onPostExecute(result);
            runOnUiThread( () -> {
                rAdapter.notifyItemInserted(rAdapter.getItemCount()-1);
            } );
        }

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 KaHa6uc