Reputation: 11
The activities of my app have all the attribute to make them portrait:
android:screenOrientation="portrait"
The minSdkVersion of the app is 21. With Android 5.0 phones the app crashes if the device is using the autorotate setting and the app goes to background (Recents/Overview screen) and then the device is rotated.
When this happens, this is the stacktrace I get from the error:
java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.ActionMenuPresenter.updateMenuView(boolean)' on a null object reference
at android.widget.ActionMenuView.onConfigurationChanged(ActionMenuView.java:133)
at android.view.View.dispatchConfigurationChanged(View.java:9487)
at android.view.ViewGroup.dispatchConfigurationChanged(ViewGroup.java:1294)
at android.view.ViewGroup.dispatchConfigurationChanged(ViewGroup.java:1299)
at android.view.ViewGroup.dispatchConfigurationChanged(ViewGroup.java:1299)
at android.view.ViewGroup.dispatchConfigurationChanged(ViewGroup.java:1299)
at android.view.ViewGroup.dispatchConfigurationChanged(ViewGroup.java:1299)
at android.view.ViewGroup.dispatchConfigurationChanged(ViewGroup.java:1299)
at android.view.ViewGroup.dispatchConfigurationChanged(ViewGroup.java:1299)
at android.view.ViewGroup.dispatchConfigurationChanged(ViewGroup.java:1299)
at android.view.ViewGroup.dispatchConfigurationChanged(ViewGroup.java:1299)
at android.view.ViewGroup.dispatchConfigurationChanged(ViewGroup.java:1299)
at android.view.ViewGroup.dispatchConfigurationChanged(ViewGroup.java:1299)
at android.view.ViewRootImpl.updateConfiguration(ViewRootImpl.java:3417)
at android.view.ViewRootImpl$ViewRootHandler.handleMessage(ViewRootImpl.java:3599)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:145)
at android.app.ActivityThread.main(ActivityThread.java:6145)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1399)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1194)
The problem seems to be in the onCreateOptionsMenu. This is the reduced version of my main activity:
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
}
override fun onCreateOptionsMenu(menu: Menu): Boolean {
super.onCreateOptionsMenu(menu)
menuInflater.inflate(R.menu.menu_mainpages, menu)
val menuItem = menu.getItem(0)
val profilePictureView = LayoutInflater.from(this)
.inflate(R.layout.profile_image_layout,
coordinator_main,
false)
menuItem?.actionView = profilePictureView
return true
}
}
Upvotes: 0
Views: 95
Reputation: 11
The reason for this crash was using ActionMenuView as the root for my layout profile_image_layout and not setting it up correctly. Since I didn't really needed it, I switched to a different view class as root and the crashes are not happening anymore.
Upvotes: 1