Test android killing application when running out of memory - android

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.

Related

App run in background and open it again make device lag

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.

Android Program is running slow

I developed a firebase app, where one could post and you could like and react. Then, I stopped working on it. After some time, I started working on it again, when I was working on it, I found that the app now runs very slow, I had 3 layout (fragment used) and view pager added to it via adapter(before). Beforehand it used to work like a charm, but now when I move from one activity to other, the mobile device kind of like hangs. It was not behaving like this previously, why is that? Anyone facing similar problem?
First of all I would propose you allocate a larger memory to your ADB virtual device.
If this doesn't help, use Android Profiler to better understand the cause of this memory loss.
https://developer.android.com/studio/profile/android-profiler.html
Just go to your AVD device settings and disable Device frame, this will improve the speed of your emulator

Animations Crashing on some Devices

My problem is that I build an app which works fantastic on all my devices. But on my friend's phone, not only the animations of the app seem to crash, but even his whole phone reboots. I also tried putting the animation in a try block, but no luck on that so far..
Intent openDaily = new Intent("nl.plplpl.ccs.DailyActivity");
startActivity(openDaily);
try{
overridePendingTransition(R.animator.flip_in, R.animator.flip_out);
}catch(Exception e){
e.printStackTrace();
}
break;
I also thought it could be the phone though, because he's running an Alpha version of CM10.1, but tried another ROM with the same result (Maybe driver related?).
Is anyway prepared to help me out on this one?
I also thought it could be the phone though, because he's running an Alpha version of CM10.1, but tried another ROM with the same result (Maybe driver related?).
Yes, if you manage to reboot / crash the whole device it's typically something driver / kernel / .. related.
A device should never crash as a whole regardless of what your app does. If your app does something bad you should get a nice error message and get back to the home screen.
A reboot will only happen if something within the system (and therefore not within your responsibility) goes horribly wrong. E.g. the graphic driver goes into some corrupted state and there is no way to recover. There is no way to catch those types of errors. If it was just a Java Exception it would not crash.
You can sometimes see within logcat (not filtered for your app) what happens.

Android debugger weirdness

I've been having frustrating issues with the Android debugger. I can debug and step through code sometimes, then in other parts of the code (lately in try/catch situations), it goes down to the catch {} block and there is no information on the exception and it doesn't even Log.e it to console. Notice how in the screenshot I've stepped into the catch block, but there is no live variable context, its as if it is in normal content assist mode. Watch expressions show <error(s)_during_the_evaluation>.
Can anyone shed light on these frustrating issues I'm having? The weird thing that the debugger works fine in other parts of the code.
Eclipse + ADT is notorious for acting inconsistently, which often leads me to just make sure that Project > Build Automatically is checked and then simply fire up a Project > Clean....
Sometimes even that doesn't help. So I just close Eclipse and re-start it. Works most of the time.
When even this doesn't help, I close Eclipse, run CCleaner and reboot. Works every time.
Weird but true.
You can't always believe your debugger; it's an inexact science. This is especially true when there are multiple code build steps (JVM bytecode, Dalvik code, etc). The debugger often doesn't have 100% of the information necessary to reverse engineer the location in the code back to a source code line.
In the instance above, did your code actually throw an exception, or not? It sounds like it didn't, and the debugger is showing execution on that highlighted line even though it's not really going to execute it.
I would be more inclined to believe the execution of the code - if Log.e() was never called, then you never really got any exception at all.

Android app crashes on second run

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...

Categories

Resources