I have an app with an intro screen, there will be two buttons in this screen (Ok and Cancel)
If the user clicks the cancel button the application will terminate, and if the user clicks the ok button ,the main screen appears, the main screen got a back button to go back to the intro screen.
Now, my problem is I have used
finish();
for the cancel button, and what I understood is that the 'finish()' will terminate the current running activity.
Once the application is started and if the user clicks the cancel button, the app terminates, but if the user goes to the main screen and comes back to the intro screen and then click cancel the intro screen will exit(Activity responsible for the intro screen).and the main screen appears back.
This forms a continuous loop since the previous Activity (activity opened just before the intro activity) will always appear even if the user clicks the cancel button...
Does anyone have an idea how to terminate more than one activity at a time?
You can use setResult() function in your Intro Activity, and 'catch' it in Main Activity overriding OnActivityResult() function.
Related
I have an application which always has to start with a splash screen.
But after the splash screen, I want that it should go to the last activity that was visible before the application went to the background.
Also, I would like the same behaviour when the app icon is clicked.
So lets say the user was on Activity5 and then he pressed the Home button.
Now if he clicks on the App icon, then the app should start with the Splash screen but then return back to Activity5.
Could someone please help me with the above?
Thanks and regards,
Sunny
For showing splash screen and starting the same activity,when user closes your app on home button pressed,you need to override the onPause() and onResume() ,of the activity . onPause() will be called when user will press the home button,Usesharedpreferences,to store some value referencing the current activity in SharedPreferences and when user comes back to your application onResume will be called
where you can retrieve the value of the variable of sharedpreferences show up the splash screen and start the same activity again.
I have noticed the splash screen does not display when user clicks the middle button on a real device to quit an application but if user selects back button from main menu to quit app and relaunches the splash screen will display.
Question is what function is the middle button performing compared to the back pressed and is there a way to ensure the splash screen is displayed when the middle button is used to quit an application.
Thanks.
The HOME button takes the user to the home screen (also called the Launcher). The BACK button by default finishes the current activity, which usually results in the user ending up on the previous activity he was in, until he reaches the home screen. The difference is BACK will explicitly finish an Activity, whereas HOME will not.
i try to get my app done properly but i kind of stumble upon problems all the time.
So what happens:
-> home button is pressed
-> the android menu is shown
-> i click on my app again and it just shows the appname in the actionbar and a black screen. What do i have to do to come to my starting activity again?
This screen is also shown when i press the back button. On a second tap on the back button the app closes and when i start it again it starts with my startactivity...
I really don't know what i'm doing wrong here.
I'm calling finish() in the onPause, onStop and onDestroy.
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 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.