android screens Navigation on back button - android

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.

Related

How to manage android back button activity in xamarin.forms

forms app I have four screens namely main screen , screen 2 ,list screen and settings screen so main screen is the entry screen and screen 2 is the one where all the operations are performed here and from here I can navigate to list screen and settings screen ,there is a close button in this screen 2 on click of it ,it pops back to main screen .so when I click on back button in android from main screen it takes me back to screen 2 instead of exiting from the app and on the click of back button again it takes me to list screen ,so can anyone please guide me how to tackle this back button activity ?

Instructions Activity Android Studio

I would like to create activity in which it would be explained how the app is supposed to be used. On a click on a button, I would like an Activity to be opened which has next and previous buttons on the bottom. So the first screen after the click on a button would show the first instruction and you can press next to see the next instruction which opens a new screen. After going through all the instructions, I would like a Finish button to return back to the main activity.
My question is can this be made in a single activity or is it actually more activities that differ only by the text and pictures they contain?
Yes it can be done in only one activity(actually 2 if you include the main activity).
What you can do is have multiple TextViews, and when the next button is pressed, you can toggle that 1st instruction's visibility
. And so on for the next instructions. The Next/Previous buttons should determine what Textview is currently visible, so they can keep track what Textview to show next. Use switch statement

Remove state maintenance of screens Android?

I am very new developer for Android application so please ignore if there is some technical mistakes in my question.
I have five screen (Home, SR-1, SR-2,SR-3,SR-4 ) in my Android application and I can switch any screen at give time.
When we are pressing device back button it will take we to the previous screen where I was lastly.
But whenever I am pressing Home it will take me to landing screen If in this state I am pressing device back button I will take me to previous view but I want to remove this state maintenance.
(i.e. : When I am coming to Home and I pressed back button It will exit from my application)
Thank you
for each activity: you can add in AndroidManifest.xml
<activity android:name="nameofActivity"
android:noHistory="true"></activity>
From android pressing back button should exit the app :
Immediately after you start a new activity, using startActivity, make sure you call finish() so that the current activity is not stacked behind the new one.

Preventing multiple activities from stacking with a camera snap

I have read into the finish(); commands and the FLAG_ACTIVITY_CLEAR_TOP commands and also checked out Common Ware's answer on killing app, but I am not sure how to put this into my app.
Basically, I have a user click a button that takes them to the camera. The user then snaps a photo and it brings them to a layout view. The user then clicks a button that takes them to one of 2 views, depending on a some conditions.
The user is then allowed to either retake a photo, or go to the main menu (depending). My problem is, if the user goes back to the main menu, and snaps another, then another, etc...the activities stack, so when I click the 'Main Menu' button the app goes back through eached stack activity until finally it goes back to the main menu. Is there a way to kill each activity with one of these lines, so even if a user retakes a photo, they will only need to go back once to get to the main menu?
Thanks for anyhelp.
You could use the noHistory flag which would end each activity once you're away from it.
Probably though, what you really want is singleTop launch mode, that will return to your previously opened activity rather than making a new instance of it.

How to close previous screen in 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

Categories

Resources