Memory usage of an activity / thread

by Zonakusu » Tue, 20 Oct 2009 18:17:56 GMT


Sponsored Links
 Memory usage is a big isue when programming for android. When I
created the base of the application I'm currently building, I just
tested the part (activity) that I just worked on. Last week the base
was done so I could focus on other things, including performance.

My application crashed (OutOfMemory) pretty fast when I - for example
- first opened a MapActivity followed by an activity that uses the
Camera and some Bitmaps/BitmapFactory. Now a week later I optimized
much code and it doesnt crash that fast, but it still does. I started
with a max of 2 pictures until crash, now I can make up to 15 pictures
until it crashes.

One thing that caught my eye was the threading of the application.
Each time when I create a picture and return to my main activity, it
creates a new thread (at least thats what the DDMS is showing me).
Isn't this bad for memory usage?

The way I call the main activity (Profile) from the picture activity
(PreviewPicture).

Intent detailIntent = Profile.mActivity.getIntent();
PreviewPicture.mActivity.startActivity(detailIntent);
PreviewPicture.mActivity.finish();

Note: I use mActivity in PreviewPicture because this code is called
from a dialog.

This is very weird, because when I (re)open another activity like
PreviewPicture the same way, it doesnt add a thread in the DDMS.

Since BitmapFactory leaks memory I assume it will be very hard to
completely remove the posiblilty of crashing by a
OutOfMemoryException, but I want it to be as stable as possible.

I hope you guys can help me :)
--~--~---------~--~----~------------~-------~--~----~



Other Threads

1. Medium density resources for v1.5 problems with workaround

Hi,

Compile against 1.6 or higher;
Put 'regular' resources in 'drawable'
Put 'special' resources in 'drawable-hdpi-v4' and 'drawable-ldpi-v4'

The latter hides 'special' resources from 1.5 at runtime.

--
Kostya Vasilyev -- http://kmansoft.wordpress.com

21.07.2010 16:00  "richarth" <richa...@gmail.com> :

Hi,

I've created three versions of my app logo for the three different
screen densities and placed them in the relevant folders.  I want my
app to be backwards compatiable with v1.5 of Android.  I'm aware from
the following talk at IO that there is a problem with the density
matching in 1.5:

http://code.google.com/events/io/2010/sessions/casting-wide-net-android-devices.html

The recommendation was to create two copies of the medium density
drawables folder and append -v3 to the end of one of them which I've
done.  The problem I now have is that Eclipse won't compile the app
and complains that the logo resource is already defined.  Is it best
to move the medium logo to a drawable folder and alias it, or is there
a better solution?

--

2. Video playback fails when played from 3DGallery in Froyo

Are you sure you want to play via opencore and not stagefright?

And if you are using h/w codecs, make sure its chosen properly in both the
cases.





> website: 

3. R: Strange behavior of the panel for developers of Android Market.

4. Webkit browser

5. Detect user idle time

6. Android Force close dialog

7. Video playback fails when played from 3DGallery in Froyo