1

I'd like to have a button in the top left corner of one of my activities that holds the name of the activity under it on the stack. Is this possible? The button will essentially just finish the current activity, I just need to set the text to something like the label for the activity below it on the stack.

I've got a half-working solution where I just pass a string-extra to the activity wherever I start it from, which allows me to set the text to anything that makes sense. This does not work when I'm using notifications.

AmITheRWord
  • 1,363
  • 2
  • 14
  • 36

1 Answers1

3

You could also use a custom Application object as a singleton to store the name of the last known activity (setting that in each activity's onCreate), but if you're launching multiple tasks or tasks with different affinities this won't really work properly.

But question your basic assumptions here: Is what your app is doing so unusual that you need to use up a chunk of screen real estate and introduce a navigational element totally unfamiliar to Android users who expect to just use the physical back button and to see the name of the current app/activity in the title bar (not the previous one)?

Yoni Samlan
  • 37,905
  • 5
  • 60
  • 62
  • 1
    sounds like this guys boss and my boss would be best friends :) – Nathan Schwermann Dec 15 '10 at 16:34
  • What my app is doing is not so unusual that I need to use a back-button, and I'm quite sure it won't be used, but it's a requirement by the person I'm doing it for. How would I go about doing what you suggested in the first paragraph? – AmITheRWord Dec 15 '10 at 16:35
  • See this SO question: http://stackoverflow.com/questions/708012/android-how-to-declare-global-variables/708317#708317 – Yoni Samlan Dec 15 '10 at 16:38
  • 1
    And let me guess: the person you're doing it for is either an iPhone user who doesn't regularly use an Android device, or someone with an existing iPhone app who cares more about consistency of their app across platforms than the usability and familiarity of their app within the single platform a given user will actually be on? :) Pet peeve of mine and a ledge I've talked a few clients down from in the past, but if you're stuck with it, so be it. – Yoni Samlan Dec 15 '10 at 16:41
  • Someone with an existing iPhone app who cares more about the consistency of the app than the consistency of the platforms. :) I've tried to talk him out of it several times, but I'm stuck on it. I don't like it either ;) – AmITheRWord Dec 15 '10 at 16:50
  • 2
    You can find some more platform-appropriate UI patterns here: http://www.google.com/events/io/2010/sessions/android-ui-design-patterns.html – adamp Dec 15 '10 at 16:54