tags:

views:

1132

answers:

1

I recently got some fade in stuff working so that my "loading" view is an ImageView that takes up the whole screen, and then I fade in the main view (a GridView in this case) over the top of it. In the activity creation, I call:

setContentView( R.layout.loading_foo );

then when the loading AsyncTask is done, I call the following:

LayoutInflater inflater = LayoutInflater.from( getApplicationContext() );
GridView gridview = (GridView) inflater.inflate( R.layout.foo, null );

//fade in the view as it's shown
gridview.setAnimation( AnimationUtils.loadAnimation( this, R.anim.fade_in ) );

//populate the items adapter
gridview.setAdapter( new FooGridAdapter( apps ) );

//now overlay the gridview on top of the loading_springboard page
ViewGroup.LayoutParams layoutParams = new ViewGroup.LayoutParams( ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.FILL_PARENT );
getWindow().addContentView( gridview, layoutParams );

Do I need to do anything in particular to clean up the loading_foo view to reduce the amount of memory my app is using? Any other issues with this approach?

(Long time reader, first time poster)

A: 

As you are only adding more content to the window view, your initial loading_foo will be taking up space in memory, even its not visible. You have to remove that view to clean up memory.

As you say you are putting the GridView on top of the loadingscreen, i assume you are using a FrameLayout at the bottom... To free memory you should remove the first child when the gridview is fully visible and loaded... first than the loadingview can be garbage-collected and free up memory for you.

PHP_Jedi
I wasn't using a FrameLayout (see the getWindow().addContentView call) but reworking this flow to use a frameLayout (and then calling removeView once the GridView is visible) does the right thing. Thanks.
Eric