This is exactly the type of thing to be avoided.

As soon as the user leaves the activity, you have a potential memory leak.

Call getApplicationContext(), and save that reference, not the Activity.

Application context can sometimes be confusing, and causes problems when used with UI classes, but for singletons, it's just perfect.

-- Kostya

15.12.2010 13:23, KlausSK8 пишет:
Maybe you can use ActivityName.this

          mDbHelper = new NotesDbAdapter(ActivityName.this);
          mDbHelper.open();

or make a static store in a class, ie:

public class MyClass {
   public static Context contextShared = null;
}

and when the activity starts

protected void onCreate(Bundle savedInstanceState){
    MyClass.contextShared = this;
}


so, and your code:

          mDbHelper = new NotesDbAdapter(MyClass.contextShared);
          mDbHelper.open();

On 14 dez, 16:54, Tobiah<[email protected]>  wrote:
I'm making a database wrapper from the Notepad example to fit my own database.
I decided that I'd have a generic 'Row' class that I'd subclass for each
table in the database.  It would be responsible for setting and getting
and syncing data between the app and the database.

So, in the Notepad example, the NoteEdit class does this:

          mDbHelper = new NotesDbAdapter(this);
          mDbHelper.open();

But the NoteEdit class extends Activity.  I don't see that
my Row class should extend Activity.  Would it matter? If it
does, can I just extend Activity even though the Row class
will never be called as one?

Thanks,

Toby


--
Kostya Vasilyev -- WiFi Manager + pretty widget -- http://kmansoft.wordpress.com

--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to