get bigdata from mysql for android table - android

on which way I could load this data in my androidapp.
whats your expression, what do you think is the best way.
maybe I could do something like, loading 100 entries and wait until the user has seen the last one and then load again the other one. but how could I do this.
is it the best way to get data from sql with a php script or is there a better way?

There have 2 ways:
load all data into cursor
because the cursor most hold 2M data in memory,
when you scroll listview down/up,it will auto requery().
And there is no performance/memory issue by this way.
load data into cursor by page
by this method,need youself requery()
when use the first way or second way?
if you don't delete/update data when scroll listview,
i sugeest you use the first way.
else use the second way.

Related

Android SQLITE search VS ArrayList search for small amount of dataset

Suppose, In my app I have a sqlite table that can contain at most 20 row. Each row has 2 column(id, name). Where I frequently need to search by Id to get Name. For this frequent need I have two solution:
Solution 1: Get rows in a arraylist<model> and then find name from array.
Solution 2: Every time search on sqlite table.
Now please give your opinion which one is better?
Remember again, I need this search in my recycleView item, so it call so frequently.
Thanks
I don't really get what is your real intent, but if your task is to search by id often, I would use
LongSparseArray<String> idsToNames; // or LongSparseArray<Model>
Which will map primitive long to Strings in a more memory-efficient way than Map and will have a better performance than ArrayList when searching.
The advantage over querying SQLite here is that you can do it in a blocking manner instead of having to query database on a background thread every time the lookup runs.
The disadvantage is that whenever data changes in SQLite, you will have to rebuild your idsToNames map. Also, if the number of entries in SQLite will eventually grow, you will end up in a large collection. So I would recommend this approach only if the updates to the database during this session will not happen, and if the data size is always predictable or fixed.

Android database search data on EditText TextChange

I am building an android application with a database that contains more than 20,000 entries.
When i retrieve data from the database, especially when searching for data, it seems to be working slow.
Especially, when i search data based on an editText. Every time editText TextChange(), i query :
Select * from mytable where data='mydata'
And it runs slowly.
I really don't know how to make it work faster.
Hope anyone can help me!
You can create an index on just that column to make selection work faster. If your column is the second one in an existing index, this index cannot be used most efficiently.
CREATE INDEX idx_mytable_word ON mytable(word)
May be you initialize db connection every time?
Try to add pagination. it's make your app faster.

Async task with SimpleCursorList (Android sql select)

I'm relatively new to Android but I just cant google this. I have following situation:
quite large SQL db on android (need to select and load about 2000 records to ListActivity)
I use SimpleCursorAdapter so far BUT... it doesn't allow me to load data asynchronously with AsyncTask (SimpleCursorAdapter has no "add()" as e.g. ArrayAdapter does)
I know how to make it work with ArrayAdapter but then I lose the ID attribute every time the time is clicked and I want to do it the "clean" way and keep the id (not save it some place hidden)
===> For now user has to wait till all db output is parsed into GUI, it takes some time. How can I fix it to make it run faster ? I need something like SimpleCursorAdapter.add(item) or extend it but not sure ...
thnx
You should consider having some pagination mechanism, not loading everything in an ArrayAdapter but better, returning a simpleCursorAdapter with just a subset of size N of your records. When the user will reach the last row, display a button to increase N and refetch the data from your database.

Populating ListView with ORMLite

I need to populate ListView with List of objects returned from my Dao object.
The items get returned after 3 seconds, obviously to much time for the user to wait...
I'm using BaseAdapter as the ListView adapter.
2 questions:
How can get rid of the 3 seconds waiting time? Should I just retrieve the entire list of objects in a seperate worker Thread and display dialog in the meanwhile? Is there any mechanism that allows me to get the first, let's say... 20 records, display them and fetch the rest of the records while the user scrolls down the list?
If I would use cursors, rather than ORMLite, the list would then query the DB as the user scrolls down the list, releasing the objects of the hidden cells and the cells themselves, and not keeping all the objects of the cursor in the memory. How can I achieve this behavior with ORMLite?
I hope I was clear enough, despite the bad English ;)
Thanks.
You might want to load the data in an AsyncTask, and display a ProgressDialog while it loads. Lot of Android apps do this.
Cannot OrmLite return a DataProvider instead of the while list? (I too wanted to look into ORM on Android but the management decided against it "Its slow", but I still badly want it)

Binding data in Android

I have following scenario. There is OrderHeader and OrderDetail tables in SQLLite database. I have Activity where I want to display that data. There is number of fields...
The way I see it - it has to be like this:
Get data from my content provider (I have it).
Get ordinals for columns in cursor.
Get values from cursor and format/assign them
Like I said - there is MANY fields and writing this kind of code (especially #1 and #2) very tedious and boring :)
So, I've got this idea.. Since my data comes in as JSON to begin with (from web) - I can store original JSON presentation in database along with parsed-out data and when I need to bind - all I need is to query table for this column and deserialize with GSON. This way - #1 and #2 will be 3 lines instead of many. And I will work with POJO...
Does that sounds good or there is natural nice way to bind views to data from database?
Use a ListView and a SimpleCursorAdapter (or extend it).

Categories

Resources