Changes

Jump to navigation Jump to search
Line 84: Line 84:  
Most basic activities can be frozen in the datastore by implementing the write_file() method within the main activity class. This method is then called by sugar to save the activity when it is closed or when user or program commands request that the activity be saved to the datastore. Once saved, the activity can be accessed and reloaded from the journal.  
 
Most basic activities can be frozen in the datastore by implementing the write_file() method within the main activity class. This method is then called by sugar to save the activity when it is closed or when user or program commands request that the activity be saved to the datastore. Once saved, the activity can be accessed and reloaded from the journal.  
   −
The following simple write_file() method shows how both metadata and files are written. Currently, write_file() will throw an error unless somewhere you actually write an actual file to the file_path that is passed to write_file. The code below writes a dummy file within the body of write_file itself (you can do this elsewhere as long as you have a handle on the file_path variable used by write_file).  
+
The following simple write_file() method shows how both metadata and files are written. write_file() must point to a created or existing journal entry.
 +
 
 +
# Your program can explicitly create a file in write_file() and write to it. Then, the journal entry can be created from scratch.
 +
# You can download or save a file to a particular location and then change the file path for yoru datastore object to point to this file.
 +
# If your Activity is always resumed from an existing Journal entry using the Journal entry's MIME type you can use the write_file() method to save metadata without actually writing a file.  An example of this is the Read activity, which is always resumed from a Journal entry that contains a PDF.  It uses write_file() to save metadata like the page the user was reading, the zoom level of the text, etc. but does not need to write the PDF it is using back to the journal.  The existing PDF is preserved.  
 +
 
 +
The code below creates a small text file (with "hello world" written in to it) within the body of write_file itself.  
    
   class AnnotateActivity(activity.Activity):
 
   class AnnotateActivity(activity.Activity):
Line 122: Line 128:  
         #call any code that will actually initialize the activity with  
 
         #call any code that will actually initialize the activity with  
 
         #data that is read from datastore
 
         #data that is read from datastore
         self._create_ui()
+
         self._create_ui(data)
 
          
 
          
  
108

edits

Navigation menu