Dismiss top activity to background? How? - android

I've googled this and googled this. Perhaps my terminology is wrong. I have a normal activity. I have a button called go to background mode. When the user presses this button, I want the activity to just go into the background (like it would normally do on the back button)
However, I want to prompt the user with an alert dialog: "Do you wish to enter background mode?"
If the user hits "Yes" THEN go to background, if no, then stay on current screen/activity.
For this, I am overriding ONBackPressed(). If the user hits, "YES", how to I put my activity into the background?
Thanks!

If you want to close just that activity, you can just use finish(). If you want to move the entire task to the background, you use moveTaskToBack(boolean nonRoot).

What does "put into the background" mean? Android has an activity stack, once you go back one activity, you can't go back forward. So in that sense, you just close your activity.
If you want your application to keep running and do its stuff in the background, you'll have to resort to Services.

Related

Changing Activity screen when the app is not running

How can i change the screen of an activity when pressing any button on an android phone that takes one away from the running app.
I'm trying to get a blank screen to show up on the "recents" screen, instead of a snapshot of the app.
You can use this option and check if it helps you meet your need.
android:excludeFromRecents="true"
Add this to your activities in the application manifest if you do not want the app to be shown in the recent apps list. One drawback is that you would not be able to resume the app from the Recents list. Not sure if this is what you need.
The other way is to have a 'Blank Activity', which you start when your actual activity pauses. You can then finish the 'Blank Activity' on its Resume. This way, you will have your app shown on the Recents list, but with a blank screen.
You can call finish() for activity but that will kill activity. I think that will leave blank screen. Or destroy(). Try both respond with results.
you might want to change the onpause() or onclose() functions of your app. they are the last thing android execute before leaving,therefor you can change the aspect off your app just before you leave it
EDIT :
Maybe if you create PopupWindow and set it to full screen, and color black when exiting no preview would be shown, but app would still be running (idea of user DjDexter5GH) in the onpause() and onclose() functions. therefgor,when you leave,a black(or whatever you want) screen is pushed in front
you can then close it in the onrestart(is it called this?)

Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED|Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET

When these two flags are added(or set) to a new activity A, A becomes the top of task's back stack and is shown on the screen. Here HOME is pressed, and the screen shows home.
What I want: Then let's go to launcher and select the app's icon, the app comes alive again, the A is gone.
What I am confused: Then let's long press HOME and select the app, the app comes alive again, A is still THERE.
I want A disappeared, however from Launcher or from Recent. How can I make it?
I don't think there is any easy way to do this. You can either exclude your app from the Recent list or save a flag in activity A that if true call finish() in onCreate.

Handling back and home button differently

I've got an app with two screens, we can call them List and Details.
If an user is at Details and presses Home to minimize the app and then switches back I want to stay in the view and just restore, but if he presses Back I want to go back to List, I figure I can save a "Done"-button this way. But...what's the proper way to do this?
Currently I've overriden onPause and onSaveInstance but it seems they're both called in both cases.
I'm thinking about overriding onKeyDown instead, like he did; How to control Activity flow - Back button versus Home button, but that doesn't seem like a "nice" way to do it so I thought I'd check if anybody else has another idea.
Make two activities, for list and for details. When you will press the back key in the details activity it will finish and will show up the list activity.

Good Android user interface design - when to add an explicit cancel button?

I was wondering, since on Android one closes a screen by pressing the "return" round-arrow, is it still OK to have a cancel button on each screen or does it look rather clumpsy and confuse because the user might think it does something different than the return button.
Is there a good rule or even guideline for this ?
Many thanks
On each screen it's from my point of view useless, you are suppose to go to your previous screen (previous Activity since one screen is one Activity... usually) with the back button. For dismissing an AlertDialog, keyboard, ProgressDialog : back button is still ok. Where a cancel button can be added is when the user is processing a complex chain of action and in the middle of it he thinks : screw this... here a cancel button which bring him back to your home Activity is welcome.
Downloading lots of app and look at their application's flow (navigation between screens) will teach you what's intuitive, natural and what's not.
Personal thoughts.

Android: Dismissing a dialog before displaying another

My application displays alert dialogs in some cases. Also, it is possible for a user to launch my application using the VIEW/SEND intent. The scenario I am considering is, the dialog is visible, the user presses 'Home' & selects my application to View/Share a file.
I would want to dismiss the dialog before beginning with the view/share operation. Although I can maintain which dialog is visible and hide it before the operation begins, I was wondering if there is a conventional/recommended way or API, something like activity.dismissAnyVisibleDialog() that can come in handy.
Thanks a lot,
Akshay
I finally myself maintained which dialog is visible & dismissed it before displaying the next one.
-Akshay
Just close the dialog in the onPause() method (override in your activity).
This way it will be dismissed when the activity is no longer visible i.e if you switch to the home screen.

Categories

Resources