When I open my app for the first time, it launches the splash screen, then goes to a home page.
Usually when I reopen the app (by pressing the app icon) I am directed to the home page properly. However, sometimes I get the splash screen again.
This wouldn't be a problem (because it means I'm reopening the app) but when I press the back button from the home page, I see the last iteration of my app (still open and running).
So what is going on?
Thank you
Try adding launchMode="singleInstance" to your android <activity> manifest.
http://developer.android.com/guide/topics/manifest/activity-element.html#lmode
Generally the default behavior of android apps makes sense. If you have multiple activities you generally expect that pressing the back button will move you back to the previous state. It is possible to have multiple versions of the same activity in your activity stack and negating this would not be expected. If I filled out a form twice then pressed back to the first form I wouldn't expect it to contain my second form's data, for instance. But for specific types of applications this does not make sense. There are multiple ways to handle this so you need to be aware of what you app will be doing and what the expectations for your app will be.
Related
I am working on a fitness app which has a home activity which launches a workouts activity which launches a specific workout activity. In the workout activity, one may start a workout. Thereafter, one might want to then press the Home button and launch a music player or perhaps the web browser. At some point, one would probably launch the app again to return to the already running workout, but that ends up launching a new instance of the app. When I set the launchMode on the home activity to singleTask, it simply goes back to the existing home activity when I tap the launcher icon. What I would like is for it to go back to the workout in progress, which is where you would depart the app.
Essentially, I'm looking for behavior identical to iOS where it would simply restore the app to its current state if you "relaunched" the app and it was still running.
It is supposed to work as you've described. In most cases, it actually does work like that. However, there is a long-standing nasty Android bug which causes the behaviour you've described. This happens when you launch the app for the first time from an IDE (like Eclipse) or by clicking the "open" button on the Installer screen. To see if this is what you're seeing, just do this:
Go to Settings->Applications, choose your app and click "Force close"
Launch your app, do something, press the HOME button
Launch your app again.
You should return to where you left off. If not, something else bad is going on. If that is the case, please post your manifest in your question, because the problem is likely in these.
Don't try to use special launchModes to fix this. This just creates more problems.
See this answer for more information about the nasty long-standing Android bug.
I'm working on large project, so there is some logic for saving application state, and then opening correct activity(fragment) when it comes from background.
But anyway, I've found that if user navigates through my app and then minimize it - android opens it from background in different ways in following cases:
User taps on app icon (behavior: user see home activity, doesn't matter where he was, when application was minimized)
User select app from android "recent apps" (behavior: user see exactly what he saw, when the application was minimized)
So, what is the difference between launching application from background by this two ways? I always thought, that it is the same mechanism, but, obviously, I was wrong.
Thanks for any answers
You should pay atention on the folowing docs Activity and Tasks. In short words: if user start app from recents you will receive onRestart before onStart (without onCreate it means that your app was just "suspended"). You able to save screen state using onSaveInstanceState(). But in general starting from icon and from recents - different application behaviors and you should provide proper code for this ways.
UPD
As described below root cause of unexpected behaviour was additional lunchmode attribute.
From what I experience as an Android user, both are same.
The difference we usually see is how we close the app
Press back button until app close / finish()
On this state no matter how we open the apps it will go to the main screen
Press Home button
On this state depend on the app. If the app does not handle any Activity the app will same with the first state. But if the app handle something like when onPause() the Activity then finish() the apps, then whatever you open with app icon or recent apps will provide the same result.
Correct me if I am wrong
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.
Hi I have application with more than 20 activities.I want to close my app when Home button is pressed.
There is no notion of "close my app" in Android. Android will get rid of your activities, followed by your process, after some period of inactivity by the user.
You could use the launchMode and clearTaskOnLaunch flags on your root activity from your AndroidManifest.xml:
android:launchMode="singleTask"
android:clearTaskOnLaunch="true"
When you again start your app, all activities will be killed.
You don't want to do System.exit() -- that's not how the Android Activity Lifecycle normally works (read this also).
What you should do is move the App to the background with moveTaskToBack(). Android will then keep your app running in the background, and kill it if it's unused and something needs its resources later.
If you want it to close all of the open Activities when your App is no longer visible, you can set noHist = "True" for all of the child activities (leave the main activity with noHist = "False", though). This will make it where instead of reopening your application on the last Activity they were on, it will open it on the "main" activity (i.e. it will be as if they just restarted the app).
Anyhow, read through the following answers for more information: Close application and launch home screen on Android
I have the same problem. Im writing a banking app and am required, by contract, to log off the user (or exit) when the app is put into background. There are obvious security concerns there.
There are a couple of ways Im looking to do this:
1. Intercept home button (and back button for the root activity) key press events to call logoff and/or finish()
2. In the onStop() method, for every activity, detect whether the activity is being stopped due to a new activity being show - if not, assume app is being put to background so logoff and/or finish()
The first may not work if a notification is brought to the front then the user clicks home (I havent investigated yet). Or maybe there are other ways for an app to be put into the background without pressing these buttons
The second way sounds messy & difficult to maintain
Id welcome any other ideas
Drapes
I know android has been designed this way, but it seems naive to think that apps wouldnt want an applicationOnStop event
Hi guys what I understood is that u need to know when app goes in background and how to detect it and if I am wrong plz correct me----
The user can go in background if ur app does not provide any way by pressing Back key or Home Key.
You need to use methods "dispatchKeyEvent(KeyEvent event)" to get home key event or back key event and after getting the event you can execute your task.
you can even restrict user from pressing any key but u can not control the home key.
Are the physical buttons that Android phones come with standard? Specifically the back, menu, home, and search button? In my applications I assume everyone has a back button so I don't bother putting in a "soft" button to go back to a previous screen.
For some reason I can't find any official documentation on this.
Looking at http://www.androphones.com/2010-android-phones.php it appears that all of the phones have at least the back, menu and home button.
Should I just assume all phones have a back button or do I have to always code one in my apps?
The CDD describes what is required to be compatible:
http://source.android.com/compatibility/index.html
(See "Current CDD" on the left)
In this case:
7.2.3. Navigation keys
The Home, Menu and Back functions are essential to the Android
navigation paradigm. Device implementations MUST make these functions
available to the user at all times when running applications. These
functions MAY be implemented via dedicated physical buttons (such as
mechanical or capacitive touch buttons), or MAY be implemented using
dedicated software keys, gestures, touch panel, etc.Android 4.1
supports both implementations
I haven't been able to find any definitive answer one way or another. However, the documentation assumes there will always be a Back key that the OS responds to:
As the user moves from activity to activity, across applications, the Android system keeps a linear navigation history of activities the user has visited. This is the activity stack, also known as the back stack. In general, when a user starts a new activity, it is added to the activity stack, so that pressing BACK displays the previous activity on the stack. However, the user cannot use the BACK key to go back further than the last visit to Home. The adding of an activity to the current stack happens whether or not that activity begins a new task (as long as that task was started without going Home), so going back can let the user go back to activities in previous tasks. The user can get to tasks earlier than the most recent Home by selecting its root activity from the application launcher, a shortcut, or the "Recent tasks" screen.
Activities are the only things that can be added to the activity stack — views, windows, menus, and dialogs cannot. That is, when designing the navigation, if you have screen A and you want the user to be able go to a subsequent screen B and then use the BACK key to go back to screen A, then the screen A needs to be implemented as an activity. The one exception to this rule is if your application takes control of the BACK key and manages the navigation itself.
From http://developer.android.com/guide/practices/ui_guidelines/activity_task_design.html
Based on that, I would say it is safe to assume that there will always be a physical Back key.
If you are developing specifically for the android the back button is standard.
The only other thing you could do is within the menu add a 'back' option, but it is redundant at best.
Amazon Fire phone do not have a back key.
On Android platform it is generally wrong to assume that, standard defined by an entity will work everywhere. It is usually depend on device manufacturer.
if your app rely on some specific device feature, make sure that you check and recheck, if that specific feature exist on device. Some time just putting information on AndroidManifest is not enough.