I have an app that uses fragments. There is a MainActivity which contains the "home" fragment, from which you can navigate to another fragment to add or edit records. Currently, I've set the action bar's title in the home fragment's onCreate, like so;

override fun onCreate(savedInstanceState: Bundle?) {
        (activity as AppCompatActivity).supportActionBar?.title = "Project Tracker"

My problem is this: When navigating from the "editing" fragment to the "home" fragment through the nav graph (such as when the user presses a "Save" button), the title remains how I set it. However, when exiting the editing fragment by pressing the android "back" button, taking you back to the start fragment, the title is reset to the fragment's default.

enter image description here

Placing the title-setting code in onResume() similarly has no effect.

I am relatively new to android development, so please let me know if any additional information is needed.

Related posts

Recent Viewed