i am working on an application.The first screen having login.After launching the application in device and playing with it is all ok and not any issue at all.
but if at the same time user opens any other application,uses it for a while and closes this second application and then again navigate to previously open application(on which i am working),and tries to tap or manipulate or login on the application ,application gets crashed. why so behaviour?
i am facing this issue very first time and no any idea of this.
any suggestion?
Thanks.
Check out the Android app lifecycle: http://developer.android.com/reference/android/app/Activity.html.
My guess is the Activity that your user is coming back in to is overriding the onResume() method and the method is throwing an exception or you're not calling super.onResume(). That's my best guess without any more details on what your code is doing or information from your logCat.
Related
In my App, which uses an AppCompatActivity, I have a main Activity and everything else is displayed using Fragments.
However, I have noticed, when I press the home button and do something else on the phone. When I get back to the app, it crashes with an "unfortunately application has closed" error.
What I understood from my research is that the Activity and everything else gets destroyed. Once the App is opened again, everything is lost and so the application don't know what to do and it crashes.
What can I do in a case like this?
I would be happy if when the application gets re-opened it will just restart, or even better just display resume where the application left earlier.
What can I do to prevent my app from crashing?
Check your Android monitor window or firebase console if integrated with firebase crash analytics for exact exception error message.
One possibility could be error something like this,
java.lang.IllegalStateException: Can not perform this action after onSaveInstanceState
at android.support.v4.app.FragmentManagerImpl.checkStateLoss(FragmentManager.java:1341)
at android.support.v4.app.FragmentManagerImpl.enqueueAction(FragmentManager.java:1352)
at android.support.v4.app.BackStackRecord.commitInternal(BackStackRecord.java:595)
at android.support.v4.app.BackStackRecord.commit(BackStackRecord.java:574)
This can be solved by using commitAllowingStateLoss() instead of this commit().
refer this for more info http://www.androiddesignpatterns.com/2013/08/fragment-transaction-commit-state-loss.html
I have similar problem like this.
On start my app displays a splash screen and checks via network if the current user is still premium.
My problem: I started my app right before I went to bed and minimized it by pressing the home button. In the morning I launched the app again and it resumed the activity from the night. The app never really quit, my splash screen was not shown and and it couldn't check if the user is still premium.
So how can I achieve my app to be closed after a certain time (e.g. when the app is minimized)?
But the problem is there is a portion in the app where I can view videos in full screen and here I use android's default player. So when the app is minimized while watching and then again open the app onResume will not be called and cannot check whether it is a registered user or not. The video player will continue to play the video. Is there any method so that I can kill the app when the video is playing and minimised?? is there any method which is called when the app is minimised using home key press?? Is it possible in every device to detect the home keypress event and write some code there?? Please help with some fresh ideas!!!
Now I know why my reputation is always low. Thanks Dan Hulme. You are right I just want to use the app lifecycle correctly. I want to use onRestart not onResume. And that have done the work for me. Thanks all.
MY application get crash for any reason one time but with same condition next time it working well means it not crash. For This I use Uncaught exception and through a error message and kill the process by using
android.os.Process.killProcess(android.os.Process.myPid());
System.exit(10);
Now the problem is that, I have a number of Edit Text for Taking input from user capturing photos etc, at every crash application terminate and all data loose,
Now it is very irritating to fill again data. How to get rid of from this issue please Help
I want to save the state of the application when application crash,
and when I restart my application it should be start from last position where application got crash.
same as, working in application and if press Home Button, and restart application it start from last position of application where i press Home Button.
I am new in android development please help me, to get rid off from such issue
Thanks in advance
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.
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.