tags:

views:

145

answers:

2

Hi, Iam trying to make my Activity List more effective. I have an Activity List in my app, on every call its going to the database collecting some information and show it on the screen(as List).

so basiclly everytime you finish and re-call that list, it's calling onCreate.. again and again.. my problem here is with the allocation i am trying to reduce!

for example i have an Arraylist which is being allocated every time on the onCreate Method of my activity list, and many more allocations which i do onCreate.

i find it slowing my program very much, my program is very un-stable, and i try to reach to some performances... any idea how can i avoid this onCreate everytime i re-call my Activity List? mybe another technics to reduce re-allocations? Thanks, Idan.

A: 

What about making your Arraylist static, then inside onCreate() check to see if your Arraylist is null - if it is do the hard work, otherwise just leave it alone.

jax
Yes, but arraylist it's only one thing i re-allocate.. there r much more stuff i`am doing onCreate(), which i think i shouldnt allocate/declare/set again when i re-launch ListActivity.I cant run from going to database and take from there details ofcourse, so for my disadvantage i must do this expensive operation, but mybe i can earn other opearaion on re-launching.
rayman
A: 

If you're fetching data from SQLite to put in a ListView, return the data as a Cursor and create a custom CursorAdapter to work with the list. It'll be more efficient than returning an ArrayList of objects (I assume that's what you're doing).

Erich Douglass
But i am returning the data with the curser! by the curser i am retriving the data row by row from my database, and putting it in an new object, each object symbolises item in the list of my items.so now we got another array list of object. now that list of objects i have to add to my adapter list(object by object). and with that adapter i am building my getView function...and this is the list i see on the screen. ill sum it: we got two array lists here.. the items ArrayList<item>, and the adapter ArrayAdapter<item>heh guess something is wrong here right?Thanks.ray.
rayman
Ah, I see what you're doing. Can you convert your ArrayAdapter to a CursorAdapter? That way, you wouldn't need to create the intermediate array of objects - the CursorAdapter could read directly from the Cursor.
Erich Douglass
Okie,it's working fine, But now that you understand what i did, mybe you can help and tell me me how will i retrieve the item which it's checkbox has been checked? coz when i used ArrayAdapter, ive modeled every row into object, and i could just go through all objects and check by some local verb called 'checked' if true/false, but now since i am not modeling the database to objects, how will i go through all items and check who has been 'Checked' in it's checkbox button.. Thanks, Ray.
rayman