user1872489
user1872489

Reputation: 5

Saving session when closing Java program in Eclipse

I would like to know how to restore the previous inputs I made everytime I close and re-run the program in Eclipse. For example, the program lets the user add a restaurant object and add it in a vector. These restaurant objects will still be present in the vector after I close and re-run the program.

Upvotes: 1

Views: 294

Answers (3)

xoned
xoned

Reputation: 2811

Eclipse provides often interfaces for a memento. So you can restore your View or Editor easily.

For example the ViewPart:

  public void saveState(IMemento memento)
  public void init(IViewSite site, IMemento memento) throws PartInitException

But this is for saving inputs/selections.

If you want to store all your data, i prefer a (embedded) database together with the Java Persistance API or Hibernate. So you can store easily your objects in a relational database.

Upvotes: 0

Yordan Borisov
Yordan Borisov

Reputation: 1652

Zeller is right. You have to store the information somehow: in database or on the filesystem

For that you can use serialization container object such as vector ArrayList and etc. The other way is to write it to a database and on startup the program read the DB and deserialized the object.

Upvotes: 1

Sumit Singh
Sumit Singh

Reputation: 15886

One your program ended reference of all the object is lost and those object is may be destroyed by Garbage Collector.

One your object reference lost you can't get it back.

One think you can do: you have to serialization your object some where Ex: in some file and when you restart your program just read that file and get it.
Take a look of How do I serialize an object and save it to a file in Android?

Upvotes: 0

Related Questions