Skip to content

Commit

Permalink
Avoid null context in fragments.
Browse files Browse the repository at this point in the history
  • Loading branch information
pnemonic78 committed Jan 9, 2025
1 parent 2a25c2d commit 9274192
Show file tree
Hide file tree
Showing 2 changed files with 171 additions and 151 deletions.
21 changes: 10 additions & 11 deletions app/src/main/java/org/gnucash/android/app/MenuFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,16 @@ open class MenuFragment : Fragment() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
val activity = requireActivity()
if (activity is ComponentActivity) {
activity.addMenuProvider(object : MenuProvider {
override fun onCreateMenu(menu: Menu, menuInflater: MenuInflater) {
menu.clear()
onCreateOptionsMenu(menu, menuInflater)
}
activity.addMenuProvider(object : MenuProvider {
override fun onCreateMenu(menu: Menu, menuInflater: MenuInflater) {
menu.clear()
onCreateOptionsMenu(menu, menuInflater)
}

override fun onMenuItemSelected(menuItem: MenuItem): Boolean {
return onOptionsItemSelected(menuItem)
}
})
}
override fun onMenuItemSelected(menuItem: MenuItem): Boolean {
if (context == null) return false
return onOptionsItemSelected(menuItem)
}
})
}
}
Loading

0 comments on commit 9274192

Please sign in to comment.