Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8191141
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T03:51:13+00:00 2026-06-07T03:51:13+00:00

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

  • 0

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

enter image description here

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;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T03:51:15+00:00Added an answer on June 7, 2026 at 3:51 am

    You should save the data in onPause and re-populate the adapter in onResume. Things like instant messages should be saved to persistent data storage (for example, an SQLite database), and then loaded with a CursorAdapter. A lot of the details of maintaining the data load across the Activity lifecycle can be abstracted out by making use of the LoaderManager and loading the data with a CursorLoader instead.

    It also sounds like you want to have a Service running in the background that can receive messages and save instant messages to the data store even when the Activity isn’t in focus.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Yesterday I have started developing my first Metro style App using JavaScript. I've used
I have this app (contacts style) in which you can add instances to a
I have an Outlook style app. So basically I have a sidebar on the
I have an iPad app which has a funky Path-style menu which is present
I'm defining a style XML for my android app. I have some TTF files
In the iPod app, the navigation views have the default status bar style, and
We have a custom Visualforce page that is within the Account page layout. This
I am developing a webapp for ipad and have come across an issue using
In my ST2 app I have on index.html <script id=jquery type=text/javascript src=resources/js/jquery-1.8.2.js></script> <script id=masonry
I'm using Expression Blend 4 to prototype a Windows Phone 7 app. I have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.