vamshi ch wrote:
>
> This is I'm using by AsyncTask and query text strings or pieces of text
> from database.
>
Since Kristopher Micinski answered your main point, I'll toss in some
secondary remarks.
> * This is my Query..*
>
> pupils = (ArrayList<Pupil>)new Pupil()
>
That is not actually a legal cast. You can get away with it, sort of, but
it leaves you open to
ClassCastException, and you should comment it with
'@SuppressWarnings("unchecked")' and a
comment as to how you managed to guarantee type safety here.
You should cast to 'List', not 'ArrayList', in a case like this.
> .list("Grade like ? AND Classroom like ? AND Active = 1 AND
> CurrentMonthStatus != ?",
>
'LIKE' queries are slow. That's the way it is.
> new String[] {
> String.valueOf(gradeId),
> String.valueOf(classroom),
>
> Character.toString(AppConstants.PUPIL_IN_WAITLIST)
> });
>
>
> *above list moved to below adapter then it's goes to below method..*
>
> public List<?> list(String selection, String[] selectionArgs) {
>
> return DBConnector.dbAdapter.list(this, null, selection,
> selectionArgs, null, null, null);
> }
>
You don't show enough code here. The above snippet tells us nothing.
>
> *This is the method to render the data from db..*
>
> public ArrayList<Object> list(Object object, String[] columns, String
> selection,
>
Method like this should return 'List', not 'ArrayList', as a rule.
> String[] selectionArgs, String groupBy, String having, String
> orderBy) {
> try {
>
> ArrayList<Object> results = new ArrayList<Object>();
>
Declare the widest applicable type.
> Class<?> clazz = Class.forName(object.getClass().getName());
This is truly weird. You get the class from the object, get its name, then
do a no-op
of reloading and re-initializing the already loaded and initialized class.
That's whacked.
Just use object.getClass(). Why did you go through all that anyway?
... [snip] ...
> Please let me know how to make indexes, optimize my query and optimize
execution time??
RTFM.
Seriously, the manual is really your best source, combined with online
searches.
Nobu Games wrote:
>
> I got a hunch here, so I need to ask you first if you are querying that
> data from a background thread (using AsyncTask) for example. If you don't
> do that the user interface gets noticeably blocked / unresponsive for a
> moment making your activity appear "slow". By querying the data from a
> background thread you can make your activity *appear* to be "faster",
> because the UI is still able to respond to touch events and so on.
>
> If this is not the issue then it might be your database or the query
> itself.
>
> So here a few questions for you in return:
>
> - Do you query text strings or pieces of text from your database? This can
> be really really slow because SQLite usually needs to go through all
> records and scan them for matching the strings. That's especially a big
> problem with "LIKE" conditions. You can dramatically boost your database
> string search performance using
See, he already told you about 'LIKE'. You are asking for answers already
tendered.
> the FTS3 extension <http://www.sqlite.org/fts3.html>. Which comes at a
> cost of course, the database gets much bigger, but in my opinion that's
> well worth it.
>
> - Do you use (complicated) table joins? Maybe you can optimize your query
>
> - What is / what are the columns that get queried most often? It might be
> possible that you can create an indexes for these (but use them sparingly)
>
This is an RTFM item. He told you "create an index". Now *LOOK IT UP*!
> Maybe you want to post the SQL table creation code of your database tables
> and your query code.
--
Lew
--
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
---
You received this message because you are subscribed to the Google Groups
"Android Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.