Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I don't know the contents of your <code>ArrayAdapter</code> or the <code>List</code> backing it but what about making the data backing the list serializable, saving it, and then loading it when the view is recreated?</p> <p>Traditionally I've seen this appraoch used when you're trying to store data when the app is being closed or risks being killed from remaining in the background. There is a great <a href="https://stackoverflow.com/questions/4393889/how-can-i-store-an-arraylist-of-custom-objects">post on serialization</a> complete with sample code here. They walk through taking an <code>ArrayList</code> of custom objects, writing it to a file and reopening it later. I think if you implemented this approach, writing the data of your backing <code>List</code> or <code>ArrayAdapter</code> in <code>onPause()</code> before the activity is destroyed, you could then reload that file when the activtivy is recreated. </p> <p>Other approaches (a/k/a backup plans):</p> <p>(1) Easy but sloppy - If your list is some primative, like a list of strings, you could always consider writing the values individually to <code>SharedPreferences</code> and reclaiming them on reload. Just be sure to assign some unique id in the storing process. </p> <p><strong>NOTE</strong> while this may work, <code>SharedPreferecnes</code> is generally not designed to handle large amounts of data so if you're list is long I would avoid this approach. For a few data points, however, I can't see it being a problem.</p> <p>(2) Slightly harder but risky - If you're <code>List</code> backing the adapter contains objects that implement <code>parcelable</code> or are already serializable, consider passing the <code>List</code> via an <code>Intent</code> to an existing activity that is in the background and using a callback to retrieve that data when the activity is recreated. This is similar to your idea of creating a background <code>Fragment</code>. Both approaches run the risk that the <code>Activity</code> or <code>Fragment</code> you are targeting will not be there. </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload