开发者

Effective activity List

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 ve开发者_如何学JAVAry 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.


Rather than making the ArrayList static, you should keep that data in a model. You may want to use a Singleton pattern for the model, You can also create a class that extends Application, have your app use your Application class instead of the default and keep the list data there. In your manifest file, have the following line point to your application class.

<application android:name=".MyApplicationClass" android:icon="@drawable/icon" android:label="@string/app_name">

If you go with the Application approach you then call getApplication from your ListActivity and check if the data has been loaded from the DB.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜