-
Notifications
You must be signed in to change notification settings - Fork 17
Timofey Talenfeld #14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
| public void onConfigure(SQLiteDatabase db) { | ||
| super.onConfigure(db); | ||
| db.rawQuery("PRAGMA foreign_keys = ON", null); | ||
| db.rawQuery("PRAGMA journal_mode = WAL", null); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
есть встроенные методы в SQLiteDatabase для этих прагм, попробуй их заюзать.
ЖДУ ОБНОВЛЕНИЙ |
|
Замечания исправлены. |
|
Падает при старте без провайдера: FATAL EXCEPTION: AsyncTask #1 |
| /** | ||
| * Created by root on 8/9/16. | ||
| */ | ||
| public class GettingArtistsAsyncTask extends AsyncTask<Void, Void, Artist[]> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Для этого специально есть Loader'ы.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
А чем в этом случае плох AsyncTask? Я не настаиваю на нем, просто пытаюсь понять, как делать правильно. Просто у нас была лекция по background, и мы выяснили, что для небольших задач вполне себе можно использовать AsyncTask, если правильно с ним работать.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Он не привязан к жизненному циклу. И он не плох, просто лоадеры - чуть более высокая абстракция. Там есть AsyncTaskLoader, который основан на асинктаске. Плюс ты из коробки получаешь нотификации и апдейт данных при их изменении.
|
С провайдером как-то тоже не всё хорошо. Список не показывает. Error inserting genre_id=3 artist_id=122 |
|
Странно, у меня не падает провайдер, хотя я даже специально БД удаляю при запуске. |
| super.onActivityCreated(savedInstanceState); | ||
|
|
||
| if(!(getActivity() instanceof OnDetailClickListener)) { | ||
| throw new IllegalStateException("Host activity must implement " + OnDetailClickListener.class.getCanonicalName()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Лучше делать это намного раньше - когда активити впервые доступна, т.е. в onAttach. Тогда практически во всех методах жц ты можешь быть уверен, что активити реализует то, что ты хочешь.
|
|
||
| public ArtistDbOpenHelper(Context context) { | ||
| super(context, DB_NAME, null, DB_VERSION); | ||
| context.deleteDatabase(DB_NAME); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
АААА! Зачем? Каждый раз пересобирать БД??
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ты не понял, эту строку я добавил для проверки того, падает ли SQLite при создании или нет. Т.е. это был временный эксперимент, а удалить строку я забыл)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ок
ПОСМОТРЕНО, можно обновлятьЧет удаление БД повергло меня в шок. |
ContentProvider + SQLite + Fragments
Demo: https://yadi.sk/i/rD5ggFFQu7hwo (телефон)
Планшета нет, эмулятор мой ноут не потянул. В принципе архитектура там схожая, есть разветвление только на самом первом фрагменте (в java коде) на ArtistsFragment и ArtistsLargeFragment, далее они коммитят одни и те же фрагменты, поэтому поведение должно быть почти одинаково.