KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I am getting an out-of-memory condition when I use an array adapter and change screen orientation. I have made the smallest fully working code that exhibits this problem. package com.foobar.test; import java.util.ArrayList; import java.util.List; import android.app.Activity; import android.content.Context; import android.content.pm.ActivityInfo; import android.os.Bundle; import android.util.Log; import android.view.View; import android.view.ViewGroup; import android.widget.AdapterView; import android.widget.ArrayAdapter; import android.widget.ListView; public class TestAppActivity extends Activity { protected ArrayList<ListItem> mModel = new ArrayList<ListItem>(); protected ListAdapter mAdapter = null; private static Context mApplicationContext = null; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); System.gc(); setContentView(R.layout.main); if (mApplicationContext == null) { mApplicationContext = getApplicationContext(); } ListView lv = (ListView) findViewById(R.id.ListList); lv.setItemsCanFocus(true); mAdapter = new ListAdapter(mApplicationContext, lv, mModel); lv.setAdapter(mAdapter); if (savedInstanceState == null) { Log.i("test", "@@ start"); new Thread(new Runnable() { @Override public void run() { try { boolean change = true; Thread.sleep(4 * 1000); for (int ii = 0; ii < 200; ii++) { setRequestedOrientation(change ? ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE : ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); Thread.sleep(4 * 1000); change = !change; Log.i("test", "@@ change: " + (ii+1)); }
Tags (comma-separated)
Save Edits
Cancel