WebView onPause method. Memory leak. - android

On my app I have a webview that loads a webpage which contains an online broadcast. The problem is that once I exit the app it seems to keep getting data since my free memory continues to decrease. It comes back to normal only if I close the app manually.
I have found this topic here as well:
How do I pause Flash content in an Android WebView when my activity isn't visible?
I also had the problem described there: my flash content kept working even if the app wasn't on the screen (I could hear it). Now it's fixed with the code shown there, but as I said, it keeps draining memory anyway.

Related

Application freezes after few hours of playback

Have developed application with ExoPlayer. Which works fine for shorter period. After few hours of continuous playback, app freezes. Not even the back button. Don't see any logs after the freeze in the logcat of androidStudio.
I used android profiler to check with the memory. I can see native memory is increasing. The app size is 45MB. Native memory increased from 120MB to 390MB. I don't know where does this memory is keep on adding.
There is only one activity and a fragment is there in my app. Live content will be playing on start.
Don't know how to fix this. Not even the logs are helping. Sometimes app crashes. But I don't see any logs.

On accessing External applications such as Device Gallery and getting back to my application OnCreate() is called again

I'm trying to create an application where there is a need of uploading images from my mobile. In this case, when I open my Gallery and choose a image and come back to my application, onCreate() is called again due to which the TextView, EditText and the booleans which I've used earlier are cleared.
I don't want this to happen, I want all the values to remain same and when I come back from Device Gallery to my own application. Can you please help me solving this issue?
In this case, when I open my Gallery and choose a image and come back to my application, onCreate() is called again due to which the TextView, EditText and the booleans which I've used earlier are cleared.
Presumably, your process was terminated while your app was not in the foreground. This happens quite a bit in Android. While it is a bit unusual for it to happen when launching a gallery-style app, it is not out of the question, particularly on devices with limited RAM.
Activities will be destroyed and re-created in other situations as well, such as the default behavior on a configuration change (e.g., rotating the screen, changing the language, putting the device into a dedicated car dock).
Use onSaveInstanceState() to save state information for these sorts of short-term scenarios.

How do I stop the glSurfaceView when I used finish() in my android apllication

So I am making an android game, and so far it's working fairly well. I was using System.exit(0) to kill it, but I know that is an improper way to do it. So I used finish() instead, which does close the program. The problem is, that when I reopen it, the screen is blank. It seems that for some reason, the glSurfaceView isn't being released, and continues to run, and that upon reopening the game, it loses focus of it? The sounds and everything play, and my Logcats display information, so the game is in fact running, but just not the screen. Now before people start jumping on the (just let android take care of closing your app bandwagon) I have my reasons for doing so. For one, telling me that android is efficient enough to do this is a lie, otherwise we would not have the need to restart the devices every other day. Nothing more bothersome that a lag driven phone that can barely even handle an incoming call because it has so much shit on it running. So yea, I would like to be able to close the app.
So yea, how does one correctly to the glSurfaceView that it is time to close itself down? or to tell the Activities class that it needs to release it's handle to the glSurfaceView since closing the app sure doesn't do that.

startActivityForResult on Droid 3 is clearing app memory?

I have an object sitting in memory on the application that I'm using, and on a button press I do a startActivityForResult and launch the camera application, so I can attach a photo to that object. On every phone/tablet I've ever tested with (somewhere around 15 or so) it works completely fine, but for some reason with the Motorola Droid 3 (CDMA version) once the camera application starts, it's like onDestroy is called... even though it returns to my app after the photograph is snapped, all of the variables held in memory are erased. Can someone direct me as to how I can fix this please?
I'm guessing what's happening is that the camera app uses a big enough chunk of memory that android needs to destroy the paused activity. If you look at this page,
http://developer.android.com/reference/android/app/Activity.html
It shows that possibility pretty clearly.
You are seeing differing behavior on different devices because different devices have different apps loaded into memory and different amounts of memory to begin with.
If you need to save state in your app, you can hook in at onSaveInstanceState() and onRestoreInstanceState(). Here's a post that talks about it in more detail.
How to save an activity state using save instance state?
In summary, don't depend on the state being the same when you resume an activity. If you depend on that happening, you need to handle it yourself.

In my Android app, every other time I launch my app, it crashes with OutOfMemory Exception

I have an Android app that in the onCreate() method, preloads a lot of graphics.
When I test my app on my HTC Aria and launch it, it runs fine. However, if I press the back button to exit my app, and then launch the app again, it crashes with an OutOfMemoryError: bitmap size exceeds VM budget. If I then launch the app for the third time (right after it has crashed) it launches fine. Then if I close and re-launch it, it crashes again with out of memory. It continues this every-other-time-crashing pattern forever if I keep trying.
I checked to see what life cycle methods were being called and onStop() and onDestroy() are both being called when I exit the app, yet I have a feeling that something is not yet being cleaned up and that by "crashing" the app when I try to launch it the second time, it somehow free's the memory.
Any thoughts on what could be happening or how to remedy this? Please let me know if you need me to post more info. Thanks!
Info:
My app is fairly simple and only has 1 activity that plays some frame animations.
Maybe you are unnecessarily holding onto Context references? Check Avoiding memory leaks for some tips, as well as Attacking memory problems.
It sounds like something in the Activity life cycle is not quite right. Are you sure you have every start covered? http://developer.android.com/reference/android/app/Activity.html
You have onStop but do you have onDestroy? You're probably missing one of those that you need.
You may find some useful information the many answers to this question:
Strange out of memory issue while loading an image to a Bitmap object
Also, I second the "Avoiding Memory Leaks" blog post. Especially if you can trigger the same problem with orientation changes. Using "this" context when creating display objects is a sneaky way to leak the Activity context. In my own app, I managed to leak a whole chain of contexts, and would very rapidly run out of memory when doing orientation changes.

Categories

Resources