ActionBarSherlock icon indicating copy to clipboard operation
ActionBarSherlock copied to clipboard

Title text never shows when calling StartActivity() in the initial Activity lifecycle

Open tucson-tom opened this issue 11 years ago • 4 comments

This could be something specific to my setup or hardware, so I'll try to be as detailed as possible.

ActionBarSherlock appears to work fine under the normal Activity lifecycle. However, I've encountered a scenario where the title text never shows. Assume I have two activities. Let's say one is called "Main" and the other "DisplayAd". "Main" displays one of two layouts - a loading screen and the main content. On the very first run, the loading screen shows. Data is loaded over the network (the app is useless without the data). Then the activity is restarted:

Intent intent = getIntent();
finish();
startActivity(intent);

When "Main" starts again, it sees that it has data but hasn't run "DisplayAd" before, so it launches that Activity. That Activity displays an image for three seconds and then its Handler calls finish().

At this point, "Main" resumes and appears to be functional but the title text doesn't display when using ActionBarSherlock.

I'm not calling setTitle() anywhere in my code (that was my first thought since a lot of this code is copy and pasted from another project) and also tried explicitly calling setTitle() in onResume(). When I commented out the code that starts the "DisplayAd" activity, the title text appeared just fine. I also commented out the timer code that called finish() (in case it was caused by the finish() call) and just pressed the back button but nothing changed.

Moving the StartActivity() logic that starts "DisplayAd" into a Handler in "Main" and then setting a delayed message of any amount (via sendEmptyMessageDelayed(0, 250)) in onCreate() fixed the problem. The title displays as expected when the "DisplayAd" activity calls finish() and returns to "Main".

My best guess is that calling StartActivity() from within the initial set of setup calls during the usual Android Activity lifecycle (onCreate(), onStart(), and onResume()) causes ActionBarSherlock to not display the title text when the activity resumes via the back button or finish() on pre-ICS devices. I'm not sure about ICS and later.

tucson-tom avatar Oct 24 '12 00:10 tucson-tom

Actually i have the same problem with v4.2.0, but unfortunately the workaround suggested is not suitable for my case

voituk avatar Nov 08 '12 10:11 voituk

Cheers, I had just spent 20 mins trying to figure why my title wasn't updating - this solved my issue.

highlycaffeinatedcode avatar Dec 06 '12 14:12 highlycaffeinatedcode

Please add a test case to the known-bugs sample on the dev branch.

SimonVT avatar Jan 23 '13 18:01 SimonVT

This issue cannot be reproduced when it's in the known-bugs sample because the Activity must be the first activity of the app. When it's called from another activity, the bug doesn't occur.

I created a test app to reproduce this issue. Built with ActionBarSherlock v4.3.1. https://github.com/anolivetree/ActionBarSherlock-Issue677 I could reproduce it on Desire(2.2) and 2.2 emulator.

ActivityA starts ActivityB in onStart(). If you go back to ActivityA, the title text of Acitivity is missing.

When you go back to ActivityA, onConfigurationChanged() of ActionBarView is called and mTitleLayout is recreated. However, onMeasure() is not called. As a consequence, both width and height of mTitleLayout are 0. I think this is why title text is not shown.

anolivetree avatar May 27 '13 03:05 anolivetree