0

I'm learning how to use SQLite Databses, and I have a gist of how to use them with simple data, for example I know I can store names, and emails of data type TEXT into a table. Now, I would like to apply that same thing to a more complex object, storing my Alarm object. My alarm looks like

 public class Alarm {
    public int st;
    public String name;
    public String time;
    public String date;
    public long mili;   ///calender time
    public Intent intent;
    public PendingIntent pendingIntent;
    public AlarmManager manager;
    public Alarm(String name, String time, String date, int st, long mili, Intent intent, PendingIntent pendingIntent, AlarmManager manager){
        this.name = name;
        this.time = time;
        this.date = date;
        this.st = st;
        this.mili = mili;
        this.intent = intent;
        this.pendingIntent = pendingIntent;
        this.manager = manager;
    }
}

I know I can use data types such as INTEGER and TEXT to store my strings and integers, but is there a way to store things such as intents, pending intents, and managers. I have a list of these objects, that I use in different classes so I need to be able to access each alarm objects intent, pending intent, and manager, so that I can reset and cancel alarms, therefore I find it easy to store that data in the object. However I'm not sure of this can actually be saved in an SQL table. Would anyone share some tips with me?

JOhAnn4187
  • 77
  • 1
  • 10
  • 1
    The only way I can think of doing this would be to serialize your Java objects into a binary array, and then save that. But, please _don't_ do this. Databases are meant for storing data, not Java objects. Even ORM frameworks ultimately convert the objects back to regular data before persisting them. You should find an alternative to what you are currently considering. – Tim Biegeleisen Dec 10 '18 at 06:16
  • @TimBiegeleisen, okay thanks, I assumed as much when I couldn't find info on this, but I wanted to make sure before I started fiddling with my working code. – JOhAnn4187 Dec 10 '18 at 06:36
  • Possibly duplicate of this https://stackoverflow.com/questions/1243181/how-to-store-object-in-sqlite-database – Salman Saleem Dec 10 '18 at 06:42
  • @SalmanSaleem, this seems like a good way to go about it. Is there any specific file that i should actually save my object to when serializing it? Is there a specific file, like SharedPrefrences or something that I should use, or could i just use something like alarmsList.txt? – JOhAnn4187 Dec 10 '18 at 07:02
  • @SalmanSaleem is there a specific folder that it shoul go in (perhaps raw?) – JOhAnn4187 Dec 10 '18 at 07:03

1 Answers1

0

Is there any specific file that i should actually save my object to when serializing it? nope, you code, then save it in db in byte stream.. Is there a specific file, like SharedPrefrences or something that I should use, or could i just use something like alarmsList.txt? have a look at this https://android.jlelse.eu/parcelable-vs-serializable-6a2556d51538 perhaps you will get more information is there a specific folder that it shoul go in (perhaps raw?) not necessary Thank you!

Salman Saleem
  • 261
  • 1
  • 3
  • 10