Android community from activities - android

I have a problem with activities. I have a 4 activities. First is menu, second and thirth are other menus and fourth is screen with help. In every for 3 menu screens I have a button which start activity help. In help activity I have a info about application and button. I want to this button when user use it he back to last active activity. For better understanding: when I am in first menu and click help button, activity "help" is starting and when I click button "back", activity "menu1" is starting. Algorithm must be the same for other menus. Can you help me?

Normally, if you start activity Y from activity X, when activity Y finishes, the control automatically returns to activity X.
Thus, let's say you have three menu activities A, B, C and help activity D. Then, if you do A -> D, then when D finishes, you'll be back on A. If your flow is A -> B -> D, then after D finishes, you should end up back on B. Lastly, if your flow is A -> B -> C -> D, then upon finishing of D, you should come back to C. This is something Android should do for you automatically without you having to code anything special.
Or did I misunderstood your requirements?

Related

Always have Activity on bottom of back stack

I have an App with a Navigation Drawer design and some activities (I know working with Fragments would probably be easier here but that wasn't feasible).
When the user clicks a drawer item, the according Activity is started with FLAG_ACTIVITY_REORDER_TO_FRONT. The up button should always take the user back to the start activity A, so when the up button is pressed I also start the A activity with the same flag.
Consider the following (capital letters are the activities, trying to visualize the backstack here):
A
user starts B from the drawer
A -> B
user presses up button, brings A in front
B -> A
user presses back button finishing A going back to B
B
user presses back button again which exits the application, but imho the user should always see the start Activity A again before leaving the app.
How would / did you guys solve this?
EDIT: #Neil, with that is: If I have
A -> B
and from there via drawer go to C I have
A -> B -> C
If the user now presses the Up button and I just close C instead of bringing A to the top, the user will be back in B which would be wrong because C is (navigationwise) not under B but they are 'siblings'.
Try to make the launchMode of that Activity B to SingleTask in your manifest file like this :
android:lanchMode="singleTask"
Your activity will not be called again.

Understanding Intent.FLAG_ACTIVITY_CLEAR_TOP

As per the image shown above, I have some queries. It is requested to read each step in order :-
Each block is an Android Activity
Arrow represents the Stack Direction - the order in which activities are opened(A is started when the app was first launched)
Here when the User reaches ACTIVITY F and want to open activity Z (We are using Flag_Activity_clear_top) for the same.
After that from ACtivity Z when the user wants to open the Activity D.
****Our Requirement at this step is - When the Activity D is opened and the user do presses the back button - I WANT THAT USER SHOULD BE REDIRECTED BACK TO THE ACTIVITY C, AFTER THAT ACTIVITY B and so on..** **
Currently when we press back from the activity D(after coming from Z), then we are being redirected to the Activity Z.
CLEAR_TOP isn't good, because if you open an activity that way, it will remove the whole stack and that doesn't sound like what you want.
Try this:
When starting activity E (from D), F (from E) and Z (from F), do it with the flag "FLAG_ACTIVITY_NO_HISTORY". This flag will prevent the new activity to appear in the back stack.
Keep in mind that any activity you open this way will not be registered in the back stack. So, if you hit back while (for example) you're in F, it will return to D.
Hope this helps!
->Incase anyone is facing the same issue. Try sending the intent along with the flags 'FLAG_ACTIVITY_CLEAR_TOP' and 'FLAG_ACTIVITY_SINGLE_TOP'.
->Example mentioned in the docs: link
Consider a task consisting of the activities: A, B, C, D. If D calls startActivity() with an Intent that resolves to the component of activity B, then C and D will be finished and B receives the sentIntent, resulting in the stack now being: A, B.

Android back button and resume activity

I have this issue.
I have an actvity A that starts other activity B (by onclick - button).
In B I have one back button to come back to activity A. I press it.
Now that I'm in A, I press again button to go to B.
If I use android back button (I'm in B) I come back to A first and then to B.
But now, if i press android back button again, I don't go to previus activity of A or it exit from app. I come back to B !!!
How can I prevent this behavior ?
The back button of activity B should not start activity A, but close activity B with finish:
http://developer.android.com/reference/android/app/Activity.html#finish%28%29
Note that it is probably bad user interface design to have a "back" button on the interface. This official Android page says "Don't use labeled back buttons"
http://developer.android.com/design/patterns/pure-android.html
if you wish your custom back button to swap between the acivities A and B, you should simply launch intents, that will do.
I believe your problem is with the android back button. If you do not want go to the previous activity with this action, you can write in the manifest file under the <activity> tags for both A and B activities - android:noHistory="true". Doing this will exit from the app. as the activity stack was storing none of the activities, but such a requirement is quite confusing UI approach.

Android - finish activity and exit app

I have an application which consists 3 activities - lets call them A, B & C.
From activity A You can get to activity B, from B to C and from C to A (By pressing the back button).
On activity A I have an exit button (I know it`s not recomandded on android, but a lot of users are asking for it, so I decided to add it).
Anyway the problem is that: activity B has a timer, when the timer is finished it starts an intent that starts activiy C and calls finish() on activity B.
When the user then press back on activity C he gets to activty A - and then when he presses the exit button (this button only preforms finish()), it pops up activity B again. How can I prevent it from happen?
Thanks!
Idea: set a isFinished field in your Application to true and call finish(). All activities check if isFinished in their onResume() and if true they finish().
I'm not sure I understand how you end up at A when going back from C. Shouldn't it go back to B (logically, I mean. I know you want it to go to A)? In fact, that seems to kind of be what's happening. B is getting relaunched, but A appears on top of it, so that when you finish A, B (which was under it) is now shown.
It sounds like you don't want B to be part of the history stack, so maybe when you launch B, you should launch it with the no history flag.
You activity b is not finished thats what i can figure out it is still in running state so when all other actitivties are finished it shows up please chekc if it is finished or not

Android: Multiple singleTasks within a single Application: problem with <HOME>

I have 2 activities declared as singleTask in my application. The reason for this is, with standard mode, pressing "HOME" in one activity (say A) and launching another (say B), still shows activity A.
However, a new problem arises because of this.
A -> "HOME" -> B (Result : B, Expected Result: B) -> "BACK" -> (Result:A, Expected Result: Home Screen)
Any ideas why?
One thing that doesn't make sense:
pressing "HOME" in one activity (say
A) and launching another (say B),
still shows activity A.
However, a new problem arises because
of this.
A -> "HOME" -> B (Result : B, Expected
Result: B)
If pressing home in A and launching B still shows A is your goal with two singleTasks, then how can A -> HOME -> B have an expected result B for you?
Now I'll try and be helpful: Which Activity, A or B, handles the Launcher intent?
A -> HOME -> B (Result: B) would make me guess that B is that Activity that does, and if that is the case, your being at A before pressing HOME would mean that your stack would be something like A above B (A displayed), so pressing Home and launching B would make your stack B above A (B displayed).
Then if A and B are in a stack, pressing BACK will move you down from B to A (A now being displayed). This sounds like your problem.
If you want to take them to the home screen instead of moving down the stack, you will need to override the standard back button handler of the system, and whenever you need to override a system mechanic, it means you should double check what your doing is really the right way to achieve your goal.
If you post more information I will update my answer to help you sort this out.

Categories

Resources