Итак, я пришел к тому моменту, когда мне нужно реализовать базу данных SQLite для моего приложения.
Следуя "Руководству Busy Coder для Android Development", я создал класс DatabaseHelper, который расширяет SQLiteOpenHelper
.
Один из моих вариантов использования - запустить запрос к базе данных и отобразить результаты на ListView
в пределах Fragment
(я использую фрагменты из библиотеки поддержки).
Из того, что я понимаю, использование managedQuery()
на самом деле не подходит и даже если это было не рекомендуется из-за того, что часть логики, инкапсулированная внутри этого метода, фактически выполняется в основном потоке, в частности reQuery()
который, насколько мне известно, выполняется при перезапуске Activity
.
Итак, я впервые познакомился с классом Loader
, только чтобы увидеть это:
"The only supplied concrete implementation of a Loader is CursorLoader, and that is only for use with a ContentProvider"
Моя первоначальная мысль заключалась в том, чтобы реализовать собственный контент-провайдер и, возможно, запретить другим приложениям получать к нему доступ, тогда я прочитал следующее в документации ContentProvider
через developer.android.com:
"You don't need a provider to use an SQLite database if the use is entirely within your own application."
Я также играл с этим:
https://github.com/commonsguy/cwac-loaderex
Однако я не знаком с этим проектом и не уверен, что его можно использовать в рабочей среде.
Итак, сейчас я могу только создать кучу экземпляров AsyncTask
в моем Fragment
и правильно управлять их жизненным циклом, убедиться, что они отменены, когда это необходимо и что-то еще.
Есть ли другие варианты?