android-database

Should I create a class that inherits SQLiteOpenHelper for each table in my database?

醉酒当歌 提交于 2019-12-24 07:17:31
问题 I need to create an android app database , but I was wondering if I should create one class that inherits SQLiteOpenHelper for each table that exists in my database ? Or should I create One class : for example MyAppDatabase that inherits from SQLiteOpenHelper and create all my tables in onCreate method as well as update and delete functions ? ANy recommendations ? 回答1: You only need one database helper for all tables in a database and thus you'd use the one onCreate method for the creation of

Room database architecture entity extends error

风流意气都作罢 提交于 2019-12-23 22:06:00
问题 While using android Room i'm having the following entity: @Entity public class Call implements Parcelable { @PrimaryKey(autoGenerate = true) private long id; private String filePath; private long durationInMillis; private String phoneNumber; private int isStarred; private int isIncoming; private long timestampCreated; } All works great. But now I want my pojo (Call.class) to extends an Abstract class as following: @Entity public class Call extends BaseViewTypeData implements Parcelable { ....

Room Persistence library - Nested Object with List<Video>, @Embedded doesn't work.

a 夏天 提交于 2019-12-23 20:01:59
问题 I have a VideoList object which I want to save using room library but when i try to use @Embedded with public List list = null; it is giving me below error: Error:(23, 24) error: Cannot figure out how to save this field into database. You can consider adding a type converter for it. VideoList Class is as below. @Entity public class VideoList { @PrimaryKey public String id; public String title; public String viewType; public Integer sortingOrder = null; public String componentSlug; public

Printing a Realm Query

孤者浪人 提交于 2019-12-23 12:46:28
问题 I am migrating my existing project's database from SQLite to Realm. So there is a way to print Query like we can get/print in SQLite. SQL Query: select * from Patient where "revision=8" and (long_description like="%bone%" or code like="%bone%") order by code My Realm Query: realm.where(Patient.class) .equalTo("revision", "8") .and() .beginGroup() .like("long_description", "*bone*").or() .like("code", "*bone*") .endGroup() .sort("code"); 来源: https://stackoverflow.com/questions/49936344

SQLiteConnection databases leak when running emulator

自作多情 提交于 2019-12-19 13:59:12
问题 I was running the emulator and received the following errors about memory leak. It was interesting that the leaking database seems to be of the Google gms instead of a user database. Does anyone know how to fix it? Thanks! 09-27 15:55:07.252 2058-2068/com.google.android.gms W/SQLiteConnectionPool: A SQLiteConnection object for database '/data/user/0/com.google.android.gms/databases/metrics.db' was leaked! Please fix your application to end transactions in progress properly and to close the

SQLiteConnection databases leak when running emulator

拥有回忆 提交于 2019-12-19 13:59:03
问题 I was running the emulator and received the following errors about memory leak. It was interesting that the leaking database seems to be of the Google gms instead of a user database. Does anyone know how to fix it? Thanks! 09-27 15:55:07.252 2058-2068/com.google.android.gms W/SQLiteConnectionPool: A SQLiteConnection object for database '/data/user/0/com.google.android.gms/databases/metrics.db' was leaked! Please fix your application to end transactions in progress properly and to close the

When to save data to database, onPause() or onStop()?

元气小坏坏 提交于 2019-12-18 03:17:07
问题 I know this question has been asked a million times, I myself though that I already knew the answer and that the correct one was that the only guaranteed call is to onPause(), so you should save your data there. However, in many places of android documentation they always suggest not doing heavy work (such as writing data in database) in the onPause() method as it will delay the transition between the activities. According to Android Developer Guide in Table 1 onPause(): This method is

Android CursorLoader with selection and selectionArgs[]

孤街浪徒 提交于 2019-12-14 02:17:47
问题 I am using Loader for RecyclerView.Adapter to list items. I want to list specific items from database table. So i did: public Loader<Cursor> onCreateLoader(int id, Bundle args) { String selectionArgs1[]={"1","13","14"}; String selection1 = DatabaseOpenHelper.COLUMN_ID + " in ("; for (int i = 0; i < selectionArgs1.length; i++) { selection1 += "?, "; } selection1 = selection1.substring(0, selection1.length() - 2) + ")"; String[] projection1 =... return new CursorLoader(getActivity()

NullPointerException Android [duplicate]

北城以北 提交于 2019-12-13 22:22:53
问题 This question already has answers here : What is a NullPointerException, and how do I fix it? (12 answers) Closed 3 years ago . I am getting NullPointerException and I couldn't fix it. Could anyone please have a look at my code to see what the problem is and how to fix it. Thanks in advance. DatabeseDEO.class public class DatabaseDEO { private DatabaseHelper DbHelper; public DatabaseDEO(Context context) { DbHelper = new DatabaseHelper(context); } public DatabaseDEO() { } public ArrayList

How to Order Room results by Date as String

大兔子大兔子 提交于 2019-12-13 04:27:02
问题 I have a room database . I have a column for date and it's saved as string . I used this query for sort my column : @Query("SELECT * FROM session WHERE class_id = :classId ORDER BY session_date ASC") List<SessionEntry> getAllSessions(int classId); Result : 1398/11/25 1398/11/29 1398/12/5 1398/2/14 1398/4/25 1398/6/17 1398/6/30 1398/7/9 1398/9/14 but i want to sort like this : 1398/2/14 1398/4/25 1398/6/17 1398/6/30 1398/7/9 1398/9/14 1398/11/25 1398/11/29 1398/12/5 Is there any way I could