What I do know is that the current activity get into the onPause() mode, and the home screen activity brought to front.
My confusion starts with situation you can re-open the application from the recent tasks menu.
so what exactly happening when I'm opening the application from the recent tasks manager?
Is the activity that was foreground when the home button pressed is still somewhere in the stack?
Is there more then one activity stack on the same time?
As far as I understand it, there is no real stack (of applications). Is just that your activity has states, so whenever you are pressing the HOME button your activity in your current application just "pauses" like if it was a stand-by state so multiple applications can be in this state as long as the system doesnt require memory and kill the tasks.
So whenever you open the activity from the recent tasks its just telling the application to wake up.
First of all, here is everything you need to know about the concept of the "Up Button":
Navigation with Back and Up and some of the implementation details: Providing Ancestral and Temporal Navigation.
Generally speaking, the Up button lets you navigate up in the application hierarchy, instead of just navigating back in the application(s) back-stack.
For example, if you work with some kind of app and you get the email notification, you can open the mail client by pressing the notification. Then you can go back to you application you were working with by pressing the Back button ( back-stack ) or you can press the Up button in order to go to the mail client's 'parent' activity ( for example from some EmailMessageActivity to EmailHomeActivity ) to work with the mail client application instead of the initial application ( the back-stack usually is cleared then, so you can only go back with the Back button as far as the the Android Home screen ).
The "Recent Tasks" factor is irrelevant and misleading, it's just another way of starting a new Activity.
Related
I'm working on a launcher app that basically launches other installed apps on the device with an explicit intent and I have a edge case scenario:
An Activity (Act) creates an intent of an application (App) and starts it by calling startActivity(intent).
App get launched, my Activity going to "stop" state.
After a while I want to get back to my application so I click on "back" hard button that closes App and bring my Application to foreground (resume state).
This is the wanted behaviour.
Here is the edge case:
If I click on the "recent applications" hard button (square icon) while on App is launched, history stack is lost, and when I return to App, and click on "back" hard button - App exists to the Launcher screen and onResume of my application is being called.
I searched the web for a solution for couple of hours now, maybe I'll find a solution here.
Thanks
It seems to me you should set android:alwaysRetainTaskState true in your root activity.
I would like to know the "idea / use" of the home versus the back button. I mean obviously the home button takes you to the home screen and the back button takes you to the previous screen. What I am trying to understand is what the users / development community expect.
In other words when a user hits home in my application should I handle that event and terminate the application? Is that what the user has grown to expect or just the opposite?
Same for the back button. Do users expect the screen being departed from to be lost much like a web page would be?
What I am getting at is trying to make sure my app behaves consistent with what the user community has grown to expect.
TIA
JB
Home Button will put application in onPause() -> onStop() , again when you relaunch application, the activity will execute the method: onRestart() -> onStart() -> onResume() -> i.e. activity life cycle
and
Back button finishes or kills the current Activity on click of back button and jump back to the previous Activity which is in stack.
Generally I'd say that pressing home is like minimising on a desktop. So I would expect the app to return to where it was.
If it acts like this then I can easily switch between apps if I need to get information from them.
Pressing back should take me backwards through the things I was doing in the app and when I reach the end of the stack it should close.
home button pressing causes an intent that is used by the the launcher app to show itself .
back button is a real event that can be caught within the current app .
in general , home button should hide all apps and go to the launcher , while back button should go back to the previous screen the user saw (finish the activity or dismiss the dialog) , and go to the previous app (task ) in case the current one doesn't have any more screens to show .
The community expects that if you press the home button, your app will go to the background and be resumeable from there. Multitasking is in the core of the Android OS. To finish your activity or app when home button is pressed is unusual to android users.
The back button is when you want to go one step back, like in the browser as you said. If you are know to IOS it will act like when you press the back button there in the top left corner.
Hope this helps
I would like to know the "idea / use" of the home versus the back
button
Let me Discuss for Back Button First.
The back button behavior is inconsistent.
for Users, it is very easy to use.
for Developer, to understand what actually pressing the back button does it isn't so easy.
The back button can perform any of the following actions as Officially said by Android site :
Go back to previous screen (activity)
Dismiss a popup
Terminate a long running process
Close on-screen keyboard
Go to previous page on browser
Exit the running app when on the last activity
Return to previous app when on the last activity and the app was launched through intent from another app
When Problem Occur with BACK button?
An added problem comes when trying to understand when the back button
cancels a running operation and when not. For example, when installing
apps from Android market tapping back takes users to previous screen
and leaves the installation process running in background. I know
there's a rule that back cancels operations that are presented users
as popup progress indicators and any other cases it is used to
navigate. But is that what users expect? Do users have to think before
pressing back to understand what is going to happen?
Home Button
Home button will take users to home screen and swiping in the
multitasking menu will kill the apps if needed. As on ICS on new
phones all the buttons are on-screen the back button could simply get
disabled when user reaches the last activity if the app was launched
from launcher icon. This would make some of the confusion to make away
but still wouldn't solve all the problems.
Finally , Don't Make Users Think Navigation is some what more important. Users should always know where they will endup without thinking.
I don't think there are easy answers for this problem but I think it may help you to find workaround for your problem according to your app.
Can anyone tell me what the difference is between opening an app from the applications screen and opening it from that recently used apps list that pops up when you long-press the home button?
I didn't even know that recently used list existed until a friend managed to break my app by launching it from there. He tried twice and got the same force quit, but when he launched it from the applications screen it opened fine.
The error log told me that a nullPointerException occurred in the getCount method on my ArrayAdaptor for my ListView.
Anyway I just wondered if there was a difference that I need to know about and adapt my code to deal with?
AFAIK, If your application is completely shutted down, launch from applications screen and recently used apps list should have no difference, both refresh start your application and open your application's MainActivity (by stack-push your application's MainActivity into a newly created task)
However, as Android is multi-task OS, your application can be put into background in standby mode i.e. open your application then short-press home button, this is not same as press back button. If you haven't override these key pressed in your application, press back button several times with pop all your activities off from activity stack and finally kill your application, whereas press home button will bring System's HomeActivity into foreground hence flip your application (AKA. task with activity stack) into background.
Things becomes more interesting here, depend on which value your configure your activity's android:launchMode in AndroidManifest.xml, if you use standard or singleTop:
1. launch app from recently used apps list always bring your standby activity back to foreground, i.e. re-order activity stack.
2. launch app from applications screen will create a new instance of your MainActivity and open it, i.e. push a newly created MainActivity into activity stack, so now you have two instances in your application's activity stack
If you use singleTask or singleInstance:
2. launch app from applications screen will use the standby MainActivity (if exist) in your application's activity stack and re-open it, i.e. re-order activity stack.
Checkout Tasks and Back Stack to see how different configurations may affect your application's activity stack behaviour.
I believe there should be no difference. These are the lifecycle methods I typically see when pressing the home button from an activity, on android 2.3.4
onPause
onStop
then when I use either the icon or previous applications to navigate back, I see
onRestart
onStart
onResume
Now, in some cases the system will tell your activity to finish while you are away (or immediately when you return if an orientation change occurred). Then you will see onDestroy, and the following when you navigate back
onCreate
onStart
onResume
I don't think there is anything mysterious going on here. According to the Activity documentation, there are only four states that a process can be in, and both of these fall under background activity.
There shouldn't be any difference in how the activity is launched from history, apart from the fact that the launching Intent will have the FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY set.
Here's an easy way to think about it. All of your activities are launched form Intents. Holding down the home button allows you to open that activity using the last intent that launched it. This can give you some unexpected results however. For instance, if you are able to launch your activity from something special like a widget.
Is there any chance to remember Activity stack so when I start app next time I have same Activity stack ? For example when I start app I am on Activty_1, then I go on Activity_2 and then on Activity_3 when I stop app ( home button, app is in background until system removes app). When I start app next time I need to be on Activity_3 and when click back_button ( there is back_button on every layout on my activities and call just finish(); ) to go on Activity_2.
If your app has been completely shutted down and fresh started next time (from either app launcher or recently used list), AFAIK, there is no easy solution to retain Activity stack (it is actually called back stack from Android official dev giude) as it always get fresh created every time you fresh start your app.
If your app has been sent in background (by home button) and started next time (from either app launcher or recently used list) which is actually bring your standby app to foreground. The default configuration android:launchMode="standard" should gives the exact behaviour you described.
The behaviour of back stack navigation is quite flexible and adjustable via numbers of configuration settings, A worth reading from official dev guide talk ablout Tasks and Back Stack.
My concern is, how long will our activity be there in the stack?
What I mean is, when the home button is pressed from my app and then my app is launched again by clicking its icon, it will regain the correct place from where I pressed the home button without writing any special code for this.
I don't know whether I'm right, I think that my app is pushed to a stack, and when I launched it, it's pulled from the server.
I want to know how long will be in that stack or any other place where it is stored? Will it be replaced by some other app after pressing the home button and using many other apps?
Your activity will remain loaded until Android decides it needs the resources back. There are methods you can override in your activity to deal with this. Read more here.
Edit: See comment below for newer link.
You should also see the documentation on the Android Activity Lifecycle:
http://developer.android.com/reference/android/app/Activity.html#ActivityLifecycle
and Process Lifecycle:
http://developer.android.com/reference/android/app/Activity.html#ProcessLifecycle
http://www.edu4java.com/android_course/processes-and-threads.html#Lifecycle
There is a hierarchy of which activities will be killed first when Android needs to reclaim resources:
empty processes (hosting no activities or other application components)
background activities
service process (running a service started with startService())
visible activities (visible on screen but not in focus, such as one behind a dialog)
foreground activity