material-components / material-components/material-components-android
AppBarLayout - Crashing when setExpand animate is true
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 17.4k
- Forks
- 3.2k
- PR merge metrics
- No merged PRs in 30d
Description
Description:
Crashing after repeated call of appBarLayout.setExpanded(true, true)
Expected behavior:
Not crashing
Source code:
<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".presentation.MainActivity">
<com.google.android.material.appbar.AppBarLayout
android:id="@+id/appBar"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<com.google.android.material.appbar.MaterialToolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:layout_scrollFlags="scroll|enterAlways"
app:menu="@menu/activity_main_menu"
app:title="@string/home"
app:subtitle="@string/assets"
app:titleCentered="true"
app:subtitleCentered="true"/>
</com.google.android.material.appbar.AppBarLayout>
<include layout="@layout/content_main" />
</androidx.coordinatorlayout.widget.CoordinatorLayout>
When a back press is called, the RecyclerView inside content_main scrolls up after calling recyclerView.smoothScrollToPosition(0) then we also call appBarLayout.setExpanded(true, true). It works for a while but after repeatedly triggering both method and clicking some action menu or navigation icon while the list is scrolling the error below kicks in.
JNI DETECTED ERROR IN APPLICATION: can't call void com.google.android.material.appbar.AppBarLayout.setElevation(float) on null object
Minimal sample app repro: N/A
Android API version: 21
Material Library version: 1.10.0
Device: Pixel (emulator)
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with AppBarLayout.setExpanded(true, true) and its animation path, then examine the interaction with RecyclerView.smoothScrollToPosition(0) and menu or navigation clicks. Reproduce the repeated sequence on Android API 21 using Material Library 1.10.0; done means the sequence no longer produces the JNI null-object crash.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- android, java
- Domain
- mobile
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100