I have a an app with an IM style page, the text is displayed using a custom listview

When I leave the activity and come back I want to still have the listview with all my data in it. SO far I have tried saving the contents of my arraylist using onSavedInstance and onRestoredInstance then setting the adapter again in onRestoredInstance but that doesn’t work.
Here is my code for my activity:
private ArrayList<String> nameList = new ArrayList<String>();
private ArrayList<String> messageList = new ArrayList<String>();
private ArrayList<String> timeList = new ArrayList<String>();
Button send = (Button) findViewById(R.id.chat_send);
EditText send = (EditText) findViewById(R.id.edit_text);
ListView chat_list = (ListView) findViewById(R.id.chat_list);
MyCustomArrayAdapter myArrayAdapter = new MyCustomArrayAdapter(this, messageList, nameList,
timeList, receiverName, senderName, language_chosen);
chat_list.setAdapter(myArrayAdapter);
send.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
String new_text = edit_text.getText().toString();
String sys_time = new Time(System.currentTimeMillis())
.toString();
timeList.add(sys_time);
messageList.add(new_text);
nameList.add(username);
myArrayAdapter.notifyDataSetChanged();
chat_list.setSelection(chat_list.getChildCount()-1);
}
});
And here is the code for my Adapter
public MyCustomArrayAdapter(Context context, ArrayList<String> planetList,
ArrayList<String> NameList, ArrayList<String> TimeList,
String receiver, String sender, String language) {
super(context, R.layout.custom_chat_layout, planetList);
this.context = context;
messageList = planetList;
nameList = NameList;
timeList = TimeList;
receiverName = receiver;
senderName = sender;
language_chosen = language;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
holder = new ViewHolder();
rowView = inflater.inflate(R.layout.custom_chat_layout, parent, false);
holder.chat_name = (TextView) rowView
.findViewById(R.id.custom_chat_name);
holder.chat_time = (TextView) rowView
.findViewById(R.id.custom_chat_timestamp);
holder.chat_text = (TextView) rowView
.findViewById(R.id.custom_chat_text);
holder.chat_name.setText(nameList.get(position));
holder.chat_time.setText(timeList.get(position));
holder.chat_text.setText(messageList.get(position));
return rowView;
}
static class ViewHolder {
TextView chat_name;
TextView chat_time;
TextView chat_text;
RelativeLayout relative;
RelativeLayout relative1;
}
You should save the data in
onPauseand re-populate the adapter inonResume. Things like instant messages should be saved to persistent data storage (for example, an SQLite database), and then loaded with aCursorAdapter. A lot of the details of maintaining the data load across theActivitylifecycle can be abstracted out by making use of theLoaderManagerand loading the data with aCursorLoaderinstead.It also sounds like you want to have a
Servicerunning in the background that can receive messages and save instant messages to the data store even when theActivityisn’t in focus.