Troubleshooting guide

181
11: Using PIM applications
Export a task. 1. To import or export PIM data, use an output stream writer to export tasks from the BlackBerry®
device to a supported serial format.
ToDoList todoList = (ToDoList)PIM.getInstance().openPIMList(
PIM.TODO_LIST, PIM.READ_ONLY);
ByteArrayOutputStream byteStream = new ByteArrayOutputStream();
2. To retrieve a string array of supported serial formats, invoke
PIM.supportedSerialFormats(), and then specify the list type (PIM.TODO_List).
String[] dataFormats =
PIM.getInstance().supportedSerialFormats(PIM.TODO_LIST);
3. To write an item to a serial format, invoke toSerialFormat(). 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.
Enumeration e = todoList.items();
while (e.hasMoreElements()) {
ToDo task = (ToDo)e.nextElement();
PIM.getInstance().toSerialFormat(task, byteStream, "UTF8",
dataFormats[0]);
}
Import a task. 1. To return an array of PIMItem objects, invoke fromSerialFormat(). 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.
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");
2. To create a new task using the PIM data, invoke ToDoList.importToDo(). The
importToDo()
method saves the task; you do not have to invoke commit().
ToDoList todoList = (ToDoList)PIM.getInstance().openPIMList(
PIM.TODO_LIST, PIM.READ_WRITE);
ToDo task2 = todoList.importToDo((ToDo)pi[0]);
Delete a task. >Invoke removeToDo() on a task list.
todoList.removeToDo(task);
Close a task list. 1. Invoke todoList.close().
2. Create code that manages exceptions.
try {
todoList.close();
} catch (PimException e) {
// Handle exception.
}
Task Steps