ushahidi / Ushahidi_Android

[Deprecated] Ushahidi Android app For Ushahidi V2.x.x. Working on V3.x.x at
https://github.com/ushahidi/platform-android/
GNU Lesser General Public License v3.0
202 stars 153 forks source link

Database queries in UI thread #159

Closed andrew659 closed 10 years ago

andrew659 commented 10 years ago

Dear developers,

I am analyzing Ushahidi using a static code checker. I found some potential slow operations in Ushahidi's UI thread.

Android documentation says this: http://developer.android.com/training/articles/perf-anr.html

"Any method that runs in the UI thread should do as little work as possible on that thread. In particular, activities should do as little as possible in key life-cycle methods such as onCreate(). Potentially long running operations such as network or database operations should be done in a worker thread (e.g., via AsyncTask)."

I found the following event handlers transitively performing database queries:

com.ushahidi.android.app.ui.phone.AddReportActivity.onClick() com.ushahidi.android.app.ui.tablet.DashBoardActivity.onMapSelected() com.ushahidi.android.app.ui.tablet.DashBoardActivity.onNavigationItemSelected()

Do you think these queries affect Ushahidi's performance? If yes, perhaps moving database actions to a separate thread can help make Ushahidi super smooth in user interaction. Looking forward to your reply and hope I can help improve Ushahidi.

eyedol commented 10 years ago

@andrew659 Thanks for reporting this. I'll take a look at it.

Just curious, where is this static code checker? Anywhere I can play with it as well? Thanks

andrew659 commented 10 years ago

@eyedol The checker is implemented by me and currently it is still a research prototype. Right now, it only supports the detection of (1) slow operations in UI thread, and (2) view holder pattern violation in list view adapters. You can see issue 146 for the view holder pattern violations detected by my tool.

I am still working on studying more patterns to make the tool more useful. I can share with you an executable once it is ready for release :)

I would like to receive your precious comments to help improve my tool. If possible, I can advise Android team to incorporate such detections into lint, which is a good static tool. http://tools.android.com/tips/lint