hi guys i am finding the strange behaviour in android while launching the Application. Let me explain the senerio. I am launching my application from android's launcher page and my application starts and runs fine and after few minute i press home button and go to android home page and then go to launcher page and again select my application and it is starting it again from first but it should have resumed from the last place where i left. And when i press back button on the launch screen of second instance of my app i am able to go back to the last page where i have left. I am more confused about what was happening and it too happens sometimes only not every time. Hope you people could help me sort this problem, Hoping for better responses. Thanks in Advance.
Edit #1:
It is not happening in all the device it happens only with Samsung and Sony but works fine with LG and HTC.
To keep an activity running in the background is not in your hand. When you press the home button, your current activity goes to the background and can be killed (onDestroy() will be called) at any time depending on the need for memory of the other applications you launch.
The more apps you launch, the more chances of killing your background app is.
The behavior may be device specific - try saving your game settings in a persisted location within the 'onPause()' function, and retrieving it on 'onResume()'. Then it doesn't matter if a new activity gets launched or the old one gets called.
Related
Android studio home button problem.
I have so many activities, when I press home buttom in any activities.
Then if I restart my app.
it started from splash activity(logo activity).
However, I want to start this from activity where I pressed home button.
Can anybody figure this out?
By default, Android handles this behavior. When you press the home button, the app should go to background and at the next time when you open it, it should start from where you left off. But, Android's memory management is designed to automatically terminate minimized apps that have not been accessed in a while when memory is needed for newly launched apps.
If there is enough memory available and still your app gets terminated, that means you are not using the API's correctly. Please read this [article] to know how to handle onPause() and onResume() to achieve this behavior.
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 developed an android application with two screens. The application is working with android devices good. But i installed application in amazon kindle fire tablet launched the application started good. I navigated from 1st screen to 2nd screen and pressed home button.
And again i launched application from applications menu. application is showing 1st screen instead of 2nd screen. Common behavior of android is should show the second screen.
What i know is while press on home button the application will go for onPause() state and launch application form launcher icon it will go fore onResume and show the screen where it has previously.
But application every time calling onCreate when launching from launcher icon. This happened in Amazon kinlde fire tablet only.
I am starting the 2nd activity from 1st activity using startActivity(intent); method
May i need to use any flag for kindle fire tablet.
Please suggest me as ASAP.
Thanks in advance.
Android doesn't guarantee that once you press back from an activity, it will remain in the onPause state. It depends on how aggressive the memory killer is, or how low the device memory is. What this means is, don't count on your application being in onPause state ever.
What you could do is, save the activity state in a shared preference, and let the Application object launch the corresponding activity, restoring UI state if required.
I'm having a bit of an issue with interaction beween my app and other apps on my phone, but I'm starting to think that maybe it's working as designed? Anyway, here's the problem.
My App, call it App A is a photo-manipulation app. So a user goes in, plays around to make changes and then uses the Share button to pass it on (SEND Intent). The photo is sent to another app, chosen from the Share menu, call it App B. This stand-alone app has its own menus, completely different look and feel, etc. The user does his thing in this app for a bit, then hits the home button and goes his way to do something else.
Sometime later, he decides he wants to run my app again. He goes into the launcher, hits the icon for App A (my app), and up pops App B. Very confusing. If he happens to remember that last time he ran App A, he used the share button to get into App B, maybe he'll think to use the back button, to get back into App A. If he doesn't remember, all he knows is that he is trying to use App A, but Android is giving him App B.
(I have one app on my phone that takes over the back button for its own use so you more-or-less get stuck in App B with no way out. Ugh. You hit the icon for App A and always end up in App B)
Is there any solution to this, or is it working as designed? None of my onCreate, OnResume, onStart, etc. methods get called when this is second-open is occurring, so I can't trap it. And realistically, I can see the desire for this behavior when timelines are short - i.e. hit the home button, quickly use some other tool, and then go back to what you were doing. But with a timeline any longer than a minute or two, it gets very confusing.
Anybody else dealing with this problem? Is there a basic Android architectural issue here? Is the SEND intent being mis-used by being accepted by stand-alone apps instead of small utilities?
I think you may use Intent flag 'FLAG_ACTIVITY_NO_HISTORY'. It means starting intent never goes into activity stack.
We can launch the app in two ways, 1 is form the app, clicking on device back button till we reach the android home screen and launching the app or 2nd is from the app we can click the device home button and then we can launch.
How can we differentiate these to launches? In 2nd type launch onrestart will be called, onrestart will be called in some other cases also.
I want to do something in the 2nd type of launch.
Can any one tel me how to do this...
Thanks in advance.
When it comes to what happens when the activity is started, you may want to look at the following link in the developer site.
http://developer.android.com/reference/android/app/Activity.html#ActivityLifecycle
You may want to code based on the lifecycle of the activity rather than if the application was pushed to the background by the home key vs. by the back key. There could be different reasons the application was pushed to the background or closed. This is the expected way to handle application events.