If I have Activity A and Launch Activity B from it, then press home I go back to home screen. If I launch the activity again from the recent apps, it goes back to B as it should, but when back is pressed the Activity send me back to the Home screen not Activity A. Activity A and be are alive for the entire time. How can I make the back button function as expected? Thanks.
Don't call finish() on Activity A if you want the back button to go from Activity B to Activity A...
Pressing the Home button empties the Activity stack.
You can capture the Back button and make it do what you want, but you would have to implement your own stack of previous activities.
Related
How do I open another activity with the same button I clicked earlier? For example, I click button A and goes to Activity 1 and I click home and click button A again and must go to Activity 2.
I tried putting id on button in xml and call different activity on its java.
Imagine if the button is from HomeActivity,let the launcher activity pass an ExtraKey to the HomeActivity and again another ExtraKey at the OnBackPressed of the Activity you are navigating to after clicking the button.Set the onClickListner according to the String passed by those activities.
Is there a way to edit the activity hierarchy(if that's what it is called)? For example...
I have an app with three activities. This is the path to transition between activities.
Activity1 --> Activity2 --> Activity3
If you press the back button, it looks like this...
Activity3 --> Activity2 --> Activity1
My problem is if the app is terminated and it receives a notification, the user can go straight to Activity3. If they then press the back button, it closes the app and they can't get back to Activity1. I don't want to use intents to get to a page when the back button is pressed. Is there a way to edit the activity hierarchy? If not, what would my best option be to solve this?
I read along the documentation in this page. And obtaining clear picture of one activity starts in android. Just like this screenshot below:
Here is my case.
Activity -A called Intent to start Activity B-.
And then from Activity -B the user click Back button.
So then it returned to Activity -A.
my question is .... since now we're in that Activity -A.
Does onPaused() method called back or onResumed() method
that is called now?
When ActivityB takes the foreground, Activity A is put into the stopped state (onPause and onStop will be called). When ActivityA comes back, it will get onStart, followed by onResume.
When my program starts, it runs a mainActivity, which right away launches and loads data into another Activity. I do this because the data needs only be loaded once, in mainActivity, then sent along to the other activities!
So! With that being said, my problem is probably forseeable! When the user clicks back enough, he will get to this initial activity, and sit there... ungracefully, instead of going back to Android's main menu.
What I want to do is add something to the onResume() method of the mainActivity, so that when it is re-entered I "activate" the back button from within the code-- (a boolean flag makes sure I'm not doing this incorrectly, thus I know it was on a back click). So isn't this just popping the current Activity from the Activity Stack?
how do I pop an activity from the activity stack!
Thanks!
Instead of using the "noHistory" attribute,you can also call finish() as you launch your next activity.. It will not re-appear when you then hit the "back" button.This will close the first activity.. removing it from the stack..
Use no history option so that this activity never gets onto the backstack.
android:noHistory=["true" | "false"]
I have an Activity which displays an alert dialog priot to the content.
Also a search activity is called before this activity.
Now when i press back on this activity i am lead to a black screen (which i assume is eighter because of the dialog [unlikely] or from the search activity). Only when i press BACK twice i get to the activity i was before.
How can i get rid of this?
Thank you.
This phenomenon was caused by the search activity. to avoid this i simply added android:noHistory="true" for the Search Activity in the Manifest.