Import a task

  1. Import the required classes and interfaces.
    import java.io.ByteArrayInputStream;
    import javax.microedition.pim.PIM;
    import javax.microedition.pim.PIMItem;
    import javax.microedition.pim.ToDo;
    import javax.microedition.pim.ToDoList;
    
  2. Invoke PIM.getInstance().fromSerialFormat() to return an array of PIMItem objects. The enc parameter specifies the character encoding to use when writing to the output stream. Supported character encodings include "UTF8," "ISO-8859-1," and "UTF-16BE." This parameter cannot be null.
  3. Invoke ToDoList.importToDo() to create a new task using the PIM items.
    String[] dataFormats = PIM.toDoSerialFormats();
    
    // Write task to serial format
    ByteArrayOutputStream os = new ByteArrayOutputStream();
    PIM.getInstance().toSerialFormat(task, os, "UTF8", dataFormats[0]);
    
    // Import task from serial format
    ByteArrayInputStream is = new ByteArrayInputStream(outputStream.toByteArray());
    PIMItem[] pi = PIM.getInstance().fromSerialFormat(is, "UTF8");
    ToDoList todoList = 
       (ToDoList)PIM.getInstance().openPIMList(PIM.TODO_LIST, PIM.READ_WRITE);
    ToDo task2 = todoList.importToDo((ToDo)pi[0]);
    task2.commit();
Next topic: Delete a task
Previous topic: Export a task

Was this information helpful? Send us your comments.