I have been working on my app and it runs on the simulator fine. I loaded it into my phone and now I have a problem. It runs fine when I first start it and also if I pick home and then restart it; however, if I use the back arrow and then restart it it crashes on that time, but will work out the next time I start it. I think it has to do with some kind of memory build up, but I verified onDestroy is being called, I figured that deletes everything my program created, right?
I found the problem, I was loading a lot of bitmaps in Oncreate(), I did not realize that I had to release them under onDestroy(). I'm still a little surprized I have to do this as the API says they will be picked up by garbage collection when there is no longer a reference to them...like when my program is closed...
Related
I have some problems to my app and I don't have any idea to fix that.
I open my app and use it for a while, then I let my app run in background which means I don't close it and use my phone do other things.
But when I want to use my app again, I found that my phone becomes very lag. When I click background app button to show which app is running in background, my app jumps to screen very lag, and when I want to click it or want to close it, it will very lag too, which means maybe my app make my phone become lag.
This situation only happen when I want to open my app again or I want to slide out my app to close it. When my app is running in background and I do other things, my phone will not lag.
I don't konw what happend to my app, can anyone tell me how can I check my app,
and know what happened that I can fixed it, thank you!
Check in your application code that you have not put a heavy task on onResume() method. If possible try to take that execution in appropriate life cycle method.
Put a break point on method which is call when the application got visible and try to find out that if any function is not taking much time to execution.
Instant Run is a necromancer. It is supposed to apply changes instantly for debugging, distinct from recompiling the entire project from scratch which is a time consuming process for a fairly iterative development process.
Sometimes, it actually accomplishes instant changes as expected. In a few seconds after I am satisfied with my code changes, my application updates with the latest code running.
But then, it goes beyond that.
Sometimes, it says it gave my application the latest code which will be instantly applied to the part of the application I was viewing and debugging, but the application closes and restarts.
Sometimes, the application closes and restarts and shows up with no code changes. I can't trust the outcome, is my code wrong or is something else awry.
Sometimes, the application closes and restarts and shows up with old code. A build that should no longer exist. Resurrected from a cache graveyard that I didn't know existed. How is this possible?
Sometimes, the application closes and restarts and informs me that it is running an old version and that the only remedy is to use Instant Run.
??????????
How and under what circumstances does InstantRun do the above things, especially the part where it resurrects the old build?
I'm currently having an issue with certain Samsung devices where starting an activity with an intro animation sometimes causes the whole device to crash.
The app essentially transitions from an Activity with a VideoView to another activity with a VideoView. The video of the activity that just started stutters in a loop for about 10 seconds before the whole device crashes and restarts.
It's not crashing the device all the time, but is limited to a couple Samsung devices from what I've tested.
I've looked at crash logs of the device which currently seem to be inconclusive from what I can see.
Important but relevant note, I am finishing the activity once starting the next.
You could try to attach the debugger manually through Android Studio if your process is alive long enough after the boot sequence.
Source:
https://developer.android.com/studio/debug/index.html
One more thing you could try is to put the 'wait for debugger' instruction in your code, using the Debug.waitForDebugger() method.
Source: https://developer.android.com/reference/android/os/Debug.html#waitForDebugger()
Other than that, you could put a lot of logs in your code, then fetch them using adb logcat > crash-log.txt command from your CMD/Terminal.
How can I test or emulate what happens to my application when Android runs out of memory and kills my app? Is there a way to force it to test and debug?
EDIT: Usually the bug I am seeing is when my application dies because the user goes to other programs and returns to mine after a while, so i want to easily test that scenario
Thanks
Yes run a bunch of stuff on your computer to get it to lag works for me.
Do this to get it to do some thing on low memory like quit app. This will close app with all activities.
#Override
public void onLowMemory() {
android.os.Process.killProcess(android.os.Process.myPid())
}
Improperly load a bunch of bitmap files. ;)
Just kidding. You should just be able to throw a new OutOfMemoryError in the part of your code that you want to test. I haven't tried it, but I believe that should do what you're wanting.
If you want to see the code in the debugger when that exception is thrown, set a break point right before the throw new OutOfMemoryError(); line.
When debugger is connected, one of my activities in an Android app is displayed as a black screen. When I run the application without debugger, everything is working normally. If debugger is connected and then I disconnect it, black screen disappears and ui is displayed normally.
Any ideas why that might be?
I reproduced the problem on two phones. Restarting the phone, uninstalling app, cleaning the project didn't do anything for me.
EDIT: onCreate() in the black screen activity doesn't even get called.. though the startActivity(intent) for it gets called.
Its not like that...Usually when you debug the application it will be very slow when compared to the normal behavior. You might be performing any task in onCreate() method that takes a bit time to execute. Until that is done UI wont be display.
I suggest you to keep some debug breakpoints and analyse where it is taking much time...
This also happened to me. Black screen after calling start activity and the onCreate of the next activity is not reached.
What I did was remove all the breakpoints on the called activity and all is good.