In my app, I change the title in the ActionBar from each fragment displayed. When I first start my apps, I got a list of requests, so my title is \"My requests (20)\".
T
In my particular case, I'm developing a hybrid app with a complex native menu structure. I'd see this issue intermittently when calling a deeplink from the hybrid content that would update the selected menu option and set the title.
I tried several of the suggested fixes with not luck. But setting a custom view produced a strange result that gave me the feeling that I was dealing with a race condition.
This proved true. I found that simply overriding the activity's setTitle function and wrapping the call to super in a postDelay runnable fixed this for me:
@Override
public void setTitle(final CharSequence title) {
toolBar.postDelayed(new Runnable() {
@Override
public void run() {
MainActivity.super.setTitle(title);
}
}, 200);
}
I'm using toolbar's postDelayed as a convenience method. But you can certainly use a handler here. Hope this helps.