Wiping Activity stack - android

I'm implementing a not-so-standard navigational menu that is accessible from every screen in my app. That is to say, from every screen in my app, I can pop up a menu that will let me choose an entirely different area of the app to navigate directly to.
I have several screens that I call edit screens. They are screens where the user had chosen an item from a list of items and are able to then edit the data for that item. I do not wish for these screens to remain on the Activity stack if the user then uses the menu to navigate to some other area of the app.
This is easy enough. I can simply call "finish()" before navigating away. However, there are a couple places where it is possible to access a nested edit screen. Meaning the edit screen the user is currently on is a child of a parent edit screen. I want both off the Activity stack.
Can anyone think of a slick way to do this? The only way I can think of is to always use startActivityForResult and pass back some identifier that tells the screen to kill itself the next time it resumes.

Related

saving activity state between screen navigations

I would like to save state of an activity when you navigate away from it. For example, you have Activity A with filled in text on it and you navigate to Activity B using an intent. Well when you go back to Activity A using an Intent you lose all the text you had on that screen.
When I use the soft key back button on most android phones, the screens text stays on there, I would like to mimic that method of keeping the text on screen between navigation.
The last thing I want to do is pass parameters between all my screens, there are a lot of forms and the users dont have to follow a specific nav order.

Dragging Menu for different Activities on Android

I need help finding an approach to build a certain kind of menu for an app.
Let's say I have a menu activity and 2 other activities. My menu activity consists of 2 options.
I want to drag the "buttons" (not sure if button is the correct name in this case) sideways and while dragging, the other activity's screen starts appearing from the side.
The thing is, depending on which button I'm dragging, different screens should appear, and I couldn't find anything similar to read about.
Does anybody recommend some topic to read that could help?
How can I manage the activities in this case?

Android App: Returning to a 'dynamic' parent activity

I am making an android app. In the action bar, I have three buttons: the up button, a button that goes to a home page (essentially a restart), and an info button that describes the app.
I have set the info button to go to an activity called 'info activity' that just has some text on it. The issue is this problem: My info activity can be triggered by multiple activities in the app, so this activity does not have one parent I can name in the Android manifest for a return. I cannot find any documentation to allow one activity to return to multiple activities, depending on which the activity the 'info activity' was accessed from and use the up button navigation to return to it. Is this impossible? Or is there another way I can do what I am attempting? It seems like one activity can only have one parent.
The "Up" navigation is designed to work in a hierarchical structure and by that, I guess that means predefined structure. It's not meant to work for dynamic, ad-hoc structures.
From Android designed guide:
The Up button is used to navigate within an app based on the hierarchical relationships between screens. For instance, if screen A displays a list of items, and selecting an item leads to screen B (which presents that item in more detail), then screen B should offer an Up button that returns to screen A.
If a screen is the topmost one in an app (that is, the app's home), it should not present an Up button.

Should I manage the activity stack or allow activities to be destroyed?

I am implementing a dashboard plus action bar UI, like in the Twitter app:
Each button on the dashboard takes the user to a different activity. A few of these activities are more important than the others, and I could imagine the user switching between them via the dashboard reasonably often.
I feel like I have two options:
Keep an activity cycle going using intent flags, so that when the user goes back to the dashboard it just pushes the dashboard activity to the top of the stack. Then when the user returns to another activity, it pushes that one to the top of the stack. No activity would be destroyed until the OS does it to gain back memory, which would be fine.
Let the activities be destroyed when the user goes back to the dashboard, then recreated later.
Which option is better in terms of performance and best practices? I like option 1 but am not sure if I'm abusing the purpose of those intent flags. And if I do go with option 1, should I also override what the back button does so that finish() isn't called?
Personally I like the first option better. This way, you would easily remember the state of the other activities when the user returns to them.
For example, if in a child activity the user scrolls some list, then goes back to the dashboard, and then returns back to the child activity, the scroll position will be where he left it off.
Regarding memory, I don't think it's an issue. Let's take a tab component for example (which is a parallel navigation controller to your dashboard). With a tab control, all the child activities (the tab activities) are never destroyed as well.
If memory does become an issue, I would combine your two ideas. For the less important activities I would implement approach 2 (destroy them on back), and for the more important activities (where state is important for the user for example), I would implement approach 1.

Preventing multiple activities from stacking with a camera snap

I have read into the finish(); commands and the FLAG_ACTIVITY_CLEAR_TOP commands and also checked out Common Ware's answer on killing app, but I am not sure how to put this into my app.
Basically, I have a user click a button that takes them to the camera. The user then snaps a photo and it brings them to a layout view. The user then clicks a button that takes them to one of 2 views, depending on a some conditions.
The user is then allowed to either retake a photo, or go to the main menu (depending). My problem is, if the user goes back to the main menu, and snaps another, then another, etc...the activities stack, so when I click the 'Main Menu' button the app goes back through eached stack activity until finally it goes back to the main menu. Is there a way to kill each activity with one of these lines, so even if a user retakes a photo, they will only need to go back once to get to the main menu?
Thanks for anyhelp.
You could use the noHistory flag which would end each activity once you're away from it.
Probably though, what you really want is singleTop launch mode, that will return to your previously opened activity rather than making a new instance of it.

Categories

Resources