ikbal
ikbal

Reputation: 1894

making a custom navigation stack in android?

In my android application I have this situation: I have a single activity across all my applicaton, say MyActivity, it contains a listview and custom views inside it. The activity has a url property so that different data loaded for each case. The problem is I can't use android's built-in stack mechanism to handle navigation. For example when I try CLEAR_TOP flag it doesn't help me, I think it merges all my stack into a single activity. I think I'm going from A to B but android thinks I'm going from A to A, I don't know if this is right but seems so. I need something to handle the navigation. anybody making application with a single activity can help me better. My application is something like a web browser, thanks.

Upvotes: 0

Views: 176

Answers (2)

josephus
josephus

Reputation: 8304

just remove clear_top. when you try to launch MyActivity from itself, android will treat it as a separate activity, thus adding a new item to the stack.

Upvotes: 1

a.ch.
a.ch.

Reputation: 8380

You may simulate the back stack by placing some data (let say your URLs) which will help you distinguish your different internal "activities" into a desired collection (i.e. LinkedList).

You will then need to override onBackPressed() method in your activity where you should poll/peek the element from your stack and refresh UI. Correspondingly you will need to push an element into your stack when you retrieve an URL and also refresh UI.

Upvotes: 0

Related Questions