android- how to go to last activity on backbutton - android

this is a problem that is really a big one .
I go to activity a ,I can go to several activities like activity b ,c and d .
if I go to activity b and I press back button , I go to activity a , that right , but when I press back button again , it goes to activity b instead of leaving activity a, I press back button again and I go to activity a and If if i press it again , then I get out of activity a .
I mean , it repeat the whole way I go and then leave it .
it shouldn't be like this ,I need to leave activity a if I press back button not repeating activities .
I can't use intent for this because of another problem that I get ,I tried finish() onBackPressed , didn't work.
How can I do so ?
thanks you

Related

How to auto press a button , when a activity is started

My main activity have 2 buttons,say A and B
I always press A, and go to 2nd activity
Please tell how i can do this automatically, like when i open my app, main activity is on, button A pressed programatically, and what user see is activity2 ,when opening the app
PLEASE DONT TELL ME TO REMOVE BUTTON B,or USE 2nd activity only
Beacause some background threads are needed to be runned on main activity,
Write below code at the end of oncreate() of mainactivity... this will surely help you
A.performClick();
buttonA.performClick();
Add this code to your main Activity

Check if activity is in tasks activity stack

So in my application i got 2 activities A and B with A as parent activity of B.
This way i am able to go from B to A by clicking the home (left top) actionbar button.
Activity B opens if i click a button in A. So thats one case how to reach B.
The other one is via a notification-click which only occurres if the app is closed. Therefor activity A is not in the task stack when the actionbar home button is clicked.
So my question is how to :
1. check if the activity A is in stack and create it manually
or
2. force activity A to create if i click the actionbar-home in B
already searched alot but didnt find a solution yet.
Hope you got one ! :)

How to make launch activity always as home activity

I have 3 activities in my app. A is the launcher activity, when I press on a button Activity B will be started, then I have a button to start Activity A or I can press back button and I can go to A. On back press previous values retained in and on button click new values will be set on A.
When I click a button in B , A will be started, I am using REORDER TO FRONT flag and singletop as launch mode. New activity is not getting created . When I press back button on A it will transit to B and again I press back button app exits. I want to have activity A on back press on B. I cannot do anything in onBackpressed() in B as B is used in several scenarios apart from the above mentioned scenario. How to manage it.
I have nor clearly understood what you are trying to do, but you could try the up-navigation pattern (http://developer.android.com/design/patterns/navigation.html#up-vs-back).
You would have to declare in your manifest that activity A is the parent activity of B and then use NavUtils.navigateUpFromSameTask(this); in your button OnClickListener.
(NavUtils is in the support.v4 package).

How to prevent reload activity in android

Have Activity A ,here am retrieving data from server .On click of button am finishing current activity and start B activity ,on click of button again i want to go A activity by finishing B activity but i dont want to reload A activity
You should have a look at the lifecyle of an activity and the activity stack. developer.android.com/guide/components/tasks-and-back-stack.html. To know more about the this developer.android.com/training/basics/activity-lifecycle/index.html. Go through the links and you should able to solve your problem.

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.

Categories

Resources