> You're running the operation in an AsyncTask, which by default runs at
> background priority. That's why it takes much longer than when you run it
> at normal priority. Try calling
> Process.setThreadPriority(Process.THREAD_PRIORITY_DEFAULT) within your
> AsyncTaskLoader implementation. This will raise that thread's priority to
> normal, so it should get more of the CPU to perform the work in question.
> Obviously this will potentially affect foreground UI responsiveness while
> the operation is running; you'll need to balance that against
> time-to-completion.
> --
> christopher tate
> android framework engineer
> On Wed, Jan 4, 2012 at 10:27 PM, andrew <avyabo...@gmail.com> wrote:
> > I've got a performance problem while fetching data from a cursor in
> > AsyncTaskLoader. Testing in android API level 10. For example 2
> > classes with cursor - TestFragmentUI fetching data in UI thread and
> > TestFragment fetching data in none UI thread.
> > public class TestFragment extends Fragment implements
> > LoaderManager.LoaderCallbacks<Object> {
> > ...
> > @Override
> > public void onActivityCreated(Bundle savedInstanceState) {
> > ...
> > getLoaderManager().initLoader(0, null, this);
> > ...
> > }
> > public android.support.v4.content.Loader<Object> onCreateLoader(
> > int id, Bundle args) {
> > return new Loader(getActivity());
> > }
> > class Loader extends AsyncTaskLoader<Object> {
> > public Loader(Context context) {
> > super(context);
> > }
> > public Object loadInBackground() {
> > ...
> > DataBaseHelper helper = new DataBaseHelper(getContext());
> > SQLiteDatabase database = helper.getReadableDatabase();
> > long start = System.currentTimeMillis();
> > Cursor data = database.rawQuery(String.format(SQL_LOAD,
> > parametr), null);
> > while (data.moveToNext()) {
> > String number =
> > data.getString(data.getColumnIndex("number"));
> > }
> > data.close();
> > Log.i(TAG, "load: " + (System.currentTimeMillis() - start));
> > ...
> > }
> > }
> > ...
> > }
> > and
> > public class TestFragmentUI extends Fragment {
> > ...
> > @Override
> > public void onActivityCreated(Bundle savedInstanceState) {
> > ...
> > DataBaseHelper helper = new DataBaseHelper(getActivity());
> > SQLiteDatabase database = helper.getReadableDatabase();
> > ...
> > long start = System.currentTimeMillis();
> > Cursor data = database.rawQuery(String.format(SQL_LOAD, parametr),
> > null);
> > while (data.moveToNext()) {
> > String number = data.getString(data.getColumnIndex("number"));
> > }
> > data.close();
> > Log.i(TAG, "load: " + (System.currentTimeMillis() - start));
> > ...
> > }
> > ...
> > }
> > In emulator TestFragment class output time that is 10 times slower
> > than output TestFragmentUI and visually it is very noticeable. On a
> > real device (I've got a DHD) 3-fold difference - still very big.
> > Any ideas?
> > --
> > You received this message because you are subscribed to the Google Groups
> > "android-platform" group.
> > To post to this group, send email to android-platform@googlegroups.com.
> > To unsubscribe from this group, send email to
> > android-platform+unsubscribe@googlegroups.com.
> > For more options, visit this group at
> >http://groups.google.com/group/android-platform?hl=en.