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?

5
  • 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. Commented Dec 10, 2018 at 6: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. Commented Dec 10, 2018 at 6:36
  • Possibly duplicate of this stackoverflow.com/questions/1243181/… Commented Dec 10, 2018 at 6: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? Commented Dec 10, 2018 at 7:02
  • @SalmanSaleem is there a specific folder that it shoul go in (perhaps raw?) Commented Dec 10, 2018 at 7:03

1 Answer 1

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!

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.