Problem with Preference - OutOfMemory Error

by Vanraj » Wed, 29 Jul 2009 10:50:57 GMT

Sponsored Links
 Hello All,

I am getting some strange problem.

I am having one

class ABC extends PreferenceCategory .. and this ABC class is added in
preference xml and drawing the UI from that XML.

Now based on events i am adding and removing the children Preference from
the PreferenceCategory(ABC).


ABC abc = new ABC(); // this is PreferenceCategory

// based on events
Preference myPref = new Preference();

this all works fine. But when i added my class which is extending the
Preference .


public* *class* MyClass *extends* Preference{

*public* MyClass(Context context) {

*             super*(context);



and code is same just object changed
*Preference myPref = new MyClass();*
*// based on events*

And i will get *out of memory error* after some time.  This sound stupid but
it is true. Now *in case of MyClass if i use CheckBoxPreference* *as it is
extending Preference i am not getting error and there is no VM Heap size
grow while running the apps*. So what is wrong with *MyClass . i am not
doing any special things in that.*

/ Vanraj


Other Threads

1. display brightness

Hi. Is there a way to check if hardware support automatic brightness? Can 
setting the system settings to auto throw an exception?


2. Help in ExpandableList

Hi I want to display data from database in ExpandableList format. I
have a room table and one switch table I want to display it in
ExpandableList so when I click on room table item then it shows switch
item of that particular room. For this I read code available in <sdk>/platforms/android-<version>/

But still I am facing problem in protected Cursor
getChildrenCursor(Cursor groupCursor) { } method.
Here is my code what should I write into getChildrenCursor.

public class ExpandableList extends ExpandableListActivity
    private int mGroupIdColumnIndex;
    SQLiteDatabase sampleDB = null;
    String SAMPLE_DBNAME = "NewHomeAutoDataBase";
        String ROOM_TABLE_NAME = "RoomTable";
        private final String LOADTYPE_TABLE_NAME = "LoadTable";
        String SWITCH_TABLE_NAME = "SwitchTable";

    private String mPhoneNumberProjection[] = new String[] {
                "RoomName", "SwitchFullName"

    private ExpandableListAdapter mAdapter;

    public void onCreate(Bundle savedInstanceState)
        sampleDB =  this.openOrCreateDatabase(SAMPLE_DBNAME,

        Cursor groupCursor = sampleDB.rawQuery ("SELECT RoomName,
SwitchFullName FROM SwitchTable ORDER BY RoomName",null);
        // Cache the ID column index
        mGroupIdColumnIndex =

        // Set up our adapter
        mAdapter = new MyExpandableListAdapter(groupCursor,
                new String[] {"RoomName"}, // Name for group layouts
                new int[] {},
                new String[] {"SwitchFullName"}, // Number for child
                new int[] {});

    public class MyExpandableListAdapter extends
SimpleCursorTreeAdapter {

        public MyExpandableListAdapter(Cursor cursor, Context context,
int groupLayout,
                int childLayout, String[] groupFrom, int[] groupTo,
String[] childrenFrom,
                int[] childrenTo) {
            super(context, cursor, groupLayout, groupFrom, groupTo,
childLayout, childrenFrom,

        protected Cursor getChildrenCursor(Cursor groupCursor) {
            // Given the group, we return a cursor for all the
children within that group

            // Return a cursor that points to this contact's phone
            Uri.Builder builder = People.CONTENT_URI.buildUpon();
            Uri phoneNumbersUri =;

            // The returned Cursor MUST be managed by us, so we use
Activity's helper
            // functionality to manage it for us.
            return managedQuery(phoneNumbersUri,
mPhoneNumberProjection, null, null, null);



3. Galaxy Tab + external screen : how to detect events from the right screen ?

4. (FaceDroid-id) WTShare HTC HD 2 does Android for noobs

5. How to identify which client called into a Remote/AIDL service?

6. How can I manually set the screen rotation?

7. Why need "" for each module from Android2.1?