How to close previous screen in android? - android

In my application, 4 screens are there. When I switch from one screen to another screen 2 or 3 times. At that time, I want to go to the 1st screen but previous screens are coming. How to close previous screens?

Are you mentioning activity as "screen"?
If yes, you can call finish() to close the current activity

Related

Next and previous button implementation in android

I have multiple screens in my app in which each screen has next and previous buttons except the first screen. when I click the previous button on 3rd screen it needs to go back to the 2nd screen and when I click next button on 3rd screen it needs to go to the 4th screen. In addition to it, the data of the screens need to be saved i.e. when I clicked the previous button on 3rd screen then the 2nd screen with already filled should be displayed. Similar with the next button also. Can anyone help me to implement this?
Thank you.

Wiping Activity stack

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.

Back Stack, Splash and TabActivity

I've searched SO and found several answers to the question in general, and have tried them all and am not having success. I really don't have my head around how the back stack works, Intent flags or the finish method. Here's my setup:
On application start-up, there's a splash screen where a couple AsyncTasks run in the background and check a couple webservers for updated content. ProgressDialogs report status. When complete (via the last onPostExecute), I launch a new Activity ("Home"). This seems to reflect some of the other posts, but I think my kludge is due to Home being a TabActivity, with 4 tabs, that initially calls setCurrentTab on tab 0.
So, using the suggestions previously posted:
android:noHistory="true" on the Splash activity
calling Splash.this.finish() after it launches the Home TabActivity
setting the Home TabActivity intent flag of Intent.FLAG_ACTIVITY_CLEAR_TOP
setting the Home TabActivity intent flag of Intent.FLAG_ACTIVITY_NO_HISTORY
The users sees the splash, the TabActivity launches, the user clicks to another tab, then hits back - the application closes (not force close - just closes back to the devices home screen).
If I don't use any of those, when the user hits back after changing to another tab, they go back to the Splash screen and are stuck (I could add a button or something to take them to the Home TabActivity but that's not optimal).
The desired result is that the user sees the Splash, gets taken to the Home TabActivity, clicks another tab, then hits back, he should be taken back to the initially set tab (tab 0).
Any insight is appreciated.
TYIA
The back stack is actually officially called the activity stack - every time you start an activity, that gets pushed onto the top of the stack (unless you set one of those flags you mentioned).
This means that unless each tab in your main app is a separate activity, then the default back key behaviour will be to leave your main app activity.
You can control this by taking over the back key or by overriding the tab switching behaviour to start different activities.

android screens Navigation on back button

I have 3 screens(xmls):
screen 1 is main menu,
screen 2 is main game and
screen 3 is showing either game over screen or game finished, screen 3's background is blurred transparent on top of screen 2.
All these navigations are creating new activity(view) and using intent to go next screen.
problem1 : if i keep on creating new activities whenever user go to screen 1 to screen 2 and finishes the game and screen 3 will have option to new game which will create new activity of screen 2, in this case, stack will be more and to go out of the game user should press back button in more number (stack numbers). I would like to know though game creates multiple activities, in stack only 3 screens should retain (or when user clicks on back button 3 times, game should come out)
problem2: user clicks on backbutton when blurred screen 3 on top of screen2 should go to main screen (screen1), as per current stage, when i click on back button its going to screen2 (from blurred screen3, which is no meaning for me)
Thanks
Problem 1 : write android:launchMode="singleTop" for each activity tag in manifest . this will avoid creation of multiple instances into history stack , will keep latest entry only .
Problem 2 write android:noHistory="true" in Screen2 activity tag of manifest,so that there will be no entry for Screen2 in history stack and back press on screen3 will show screen 1 . also have a look of Intent.FLAG_ACTIVITY_NO_HISTORY
What you want to do is set the launch mode for these activites to single top in your manifest. In your manifest set android:launchMode=singleTop for each activity you only want one instance of. For more information, checkout this.

how to go on previous screen from current screen in Android app

How do I go to previous screen from current screen in Android app? I know there is a back button on phone, but it takes me to beginning screen of my app and I want my buttons on app to work for going back to previous screen.
Back button indeed takes you to previously seen activity on screen, that launched the current one (not by means of back button). If back button takes you to beggining screen of your app means that navigation to your last activity was done from it. Try launching an activity from another one different from start activity.
What really can be problematic is ending application once at start activity by pressing back button and discovering the application switching to activity that lauched start activity (not by means of back button). In this case you should just call finish() inside onDestroy() listener method of your start activity.

Categories

Resources