public abstract @interface

Persistent

implements Annotation
sofia.app.Persistent

Class Overview

Indicates that a field in a Screen subclass should be saved to disk when the activity is dismissed and restored the next time the activity is started.

By default, the field will be set to null (or zero for primitive types) if it is not found when loading the activity's persistent storage file. (This can happen when the application is first loaded, or if new persistent fields are added during development.)

This default behavior can be changed so that a new instance of an object is created when it isn't found in storage. To do this, set the create property of the annotation to true:

    @Persistent(create = true)
Using this mode is preferable when you always want the field to refer to a valid object, since the objects are automatically created before the screen's initialize method is called. Note: When create is set to true, the type of the field must have a parameterless constructor or an exception will be thrown at runtime.

Making a field persistent places some restrictions on the type of that field and types reachable from it. If the create property is set to true, then the field's type must be a primitive type or have a parameterless constructor. Any types reachable from that type (its fields, fields in those objects, and so on) must also be primitive types or have parameterless constructors.

As with standard Java serialization, you can use the transient keyword on a field inside a persistent object to prevent that field from being written to the data store or read back out.

There are some common types that might be useful to have inside a persisted object, despite not having a parameterless constructor. Extra support has been added to make these persistable:

Summary

[Expand]
Inherited Methods
From interface java.lang.annotation.Annotation