I have a problem with navigating through activities. I am navigating from HomeActivity to Activity A. When I move from Home to Activity A, I finish the HomeActivity and starts another activity Activity B. When I start Activity B, I am not finishing Activity A. So when I finish Activity B normally it should go to Activity A. But In my case it is not working. When I call finish() in Activity B, both Activity B and Activity A is getting finished.
Can anybody suggest a way to accomplish this?
Related
In my android activity I have 3 activity A B C
But when i start A - >B - >C - >A and when i click back all activity remain A-C-B-A
I want when I press back in current activity it returns to activity A
Help
When you want an Activity to not be added to the back stack after leaving it just call:
finish();
So for example, to start Activity B from Activity A and get rid of Activity A completely:
startActivity(new Intent(ActivityA.this, ActivityB.class));
finish();
Now if you press the back button in Activity B, it will exit the app because there are no other Activities in the back stack.
For your specific situation, you can call finish on everything except Activity A, which will make Activity A the only Activity in your back stack. So the back button will always send you back to Activity A no matter what Activity you press it from.
I have activity A and Activity B.
Activity A start Activity B by intent.
After Activity B have a event (example event D), I make a listener to Activity A and I want to Activity A close Activity B because i can't modify Activity B.
What is the solution in my case ?
Thanks,
I have 2 Activity A and B, A calls B so, I want to Resume parent Activity (A) when B calls finish() on its Activity. Any advice will be useful.
UPDATE:
Maybe I should mention that I use fragments, each Activity has its own fragment, I call finish() from fragment hosted inside B activity and I expect to receive Resume on fragment belongs to A.
When you call Activity B, Activity A will go to background. Unless you finish Activity A while starting Activity B, it will automatically resume when Activity B finishes.
If you are calling this,
startActivity(ActivityB.class, this);
finish();
Just remove the finish(). It should work as expected.
I am having problems with my backstack. I have a main activity that launches a FragmentActivity A which then starts an Activity B. When i call finish() on B it goes back to the main activity not A. I debugged it and A is not being destroyed until finish() is called on B but A is being skipped over.
I have a widget for my application, which need to be somewhat independent from the app.
The activity workflow should be like this:
Widget -> Activity acting as receiver
Receiver -> LoginPage or Activity A (depending on login status)
LoginPage -> Activity A
Activity A onKeyDown -> Activity B
Activity B onKeyDown -> Home Screen.
I have no problem until Activity B, which sends back to Activity A when I press onKeyDown. I'm using FLAG_ACTIVITY_CLEAR_TOP flag and finishing the Activity when starting the activity B.
When I move from ActivityA to ActivityB using the CLEAR_TOP flag, I supposed that Activity stack is cleared, then in ActivityB I finish the Activity on the onKeyDown() method, assuming that the App will be closed, but it doesnt. Why?
I'm also trying to use FLAG_ACTIVITY_CLEAR_TASK and FLAG_ACTIVITY_NEW_TASK in the receiver but I dont understand the mechanism pretty much. Any idea about this?
In fact the FLAG_ACTIVITY_CLEAR_TOP, start your activity B if its not started or it came back as the second activity on the BackStack. To finish Activity A, you can call finish() after starting Activity B or add no history flag, when starting A.
#JesusS: I doubt if u can finish ur activity in that fashion during a forward transition.
Consider a scenario of moving from Activity A to Activity B. Now if u want to kill Activity A and want to move to Activity B then call the startActivity(intent);
(where ur moving from activity A to B)
without any flags on the intent followed by the finish() on activity A.
As per my understanding u can use Intent.FLAG_ACTIVITY_CLEAR_TOP only during backward transition i.e when u already have that activity on the stack.
Consider the following scenario:
A --> B --> C --> D
Now if u want to move back from activity D to Activity A by clearing the activities u can go for Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP.
The result is that the Activities D, C, B(LIFO) will be removed from the stack and the activity A resumes by calling the onResume() of Activity A.