Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3499064
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T12:33:58+00:00 2026-05-18T12:33:58+00:00

I have created an arraylist that is made up of custom objects. Basically the

  • 0

I have created an arraylist that is made up of custom objects. Basically the user will create a class and every time a class is created, a new Lecture (my custom object) is added to the arraylist. I need to save the generated arraylist so the user’s classes will be saved even when the app is restarted.

From my understanding, I have to make my class serializable. But how exactly do I do that? And then once its serialized what do I do?

public class Lecture{

public String title;
public String startTime;
public String endTime;
public String day;
public boolean classEnabled;

public Lecture(String title, String startTime, String endTime, String day, boolean enable){
    this.title = title;
    this.startTime = startTime;
    this.endTime = endTime;
    this.day = day;
    this.classEnabled = enable;
}
//Getters and setters below
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T12:33:59+00:00Added an answer on May 18, 2026 at 12:33 pm

    You’re in luck, all of your class’ members are already serialzble so your first step is to say that Lecture is Serializable.

    public class Lecture implements Serializable {
    
        public String title;
        public String startTime;
        public String endTime;
        public String day;
        public boolean classEnabled;
    
        public Lecture(String title, String startTime, String endTime, String day, boolean enable){
            this.title = title;
            this.startTime = startTime;
            this.endTime = endTime;
            this.day = day;
            this.classEnabled = enable;
        }
    

    Next, you need to make a default constructor since serialization seems to require that. The last thing is you need to write your object out to a file. I usually use something like the following. Note this is for saving a game state so you might not want to use the cache directory.

    private void saveState() {
        final File cache_dir = this.getCacheDir(); 
        final File suspend_f = new File(cache_dir.getAbsoluteFile() + File.separator + SUSPEND_FILE);
    
        FileOutputStream   fos  = null;
        ObjectOutputStream oos  = null;
        boolean            keep = true;
    
        try {
            fos = new FileOutputStream(suspend_f);
            oos = new ObjectOutputStream(fos);
    
            oos.writeObject(this.gameState);
        }
        catch (Exception e) {
            keep = false;
            Log.e("MyAppName", "failed to suspend", e);
        }
        finally {
            try {
                if (oos != null)   oos.close();
                if (fos != null)   fos.close();
                if (keep == false) suspend_f.delete();
            }
            catch (Exception e) { /* do nothing */ }
        }
    }
    

    Reading the data back is pretty symmetric to the write so I have left that out for this answer. Also, there are still a lot of caveats to Serialized objects so I suggest you do some Google searches and read up on Java serialization in general.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created a custom dialog for Visual Studio Setup Project using the steps
I have created a PHP-script to update a web server that is live inside
I have created a UserControl that has a ListView in it. The ListView is
I have created a C# class file by using a XSD-file as an input.
I have created a few small flash widgets that stream .mp3 audio from an
i have created a workflow activity that do give the item creater of a
I have just created a mid-sized web-application using Java, a custom MVC framework, javascript.
Again i see that the @PostConstruct is firing every time even though no binding
Problem: I have a method that creates a list from the parsed ArrayList. I
I have created a listActivity with my own ListAdapter. The problem is that the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.