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).

Like

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

// based on events
Preference myPref = new Preference();
abc.addPreference(myPref);
*or*
abc.removePreference(myPref);

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*
abc.addPreference(myPref);
or
abc.removePreference(myPref);

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
ExpandableList1.java available in <sdk>/platforms/android-<version>/
samples/...

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;


    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        sampleDB =  this.openOrCreateDatabase(SAMPLE_DBNAME,
MODE_PRIVATE, null);



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

        // Set up our adapter
        mAdapter = new MyExpandableListAdapter(groupCursor,
                this,
                android.R.layout.simple_expandable_list_item_1,
                android.R.layout.simple_expandable_list_item_1,
                new String[] {"RoomName"}, // Name for group layouts
                new int[] {android.R.id.text1},
                new String[] {"SwitchFullName"}, // Number for child
layouts
                new int[] {android.R.id.text1});
        setListAdapter(mAdapter);
    }

    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,
                    childrenTo);
        }

        @Override
        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
numbers
            Uri.Builder builder = People.CONTENT_URI.buildUpon();
            ContentUris.appendId(builder,
groupCursor.getLong(mGroupIdColumnIndex));
 
builder.appendEncodedPath(People.Phones.CONTENT_DIRECTORY);
            Uri phoneNumbersUri = builder.build();

            // 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);
        }

    }
}
Thanks

-- 

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 "CleanSpec.mk" for each module from Android2.1?