Tuesday, May 11, 2010

Re: [android-developers] which is better to use to avoid mem leaks==> getbasecontext or getApplicationcontext

social hub wrote:
>
>
>
> public Context
> <http://developer.android.com/reference/android/content/Context.html>
> getApplicationContext ()
>
> Since: API Level 1
> <http://developer.android.com/guide/appendix/api-levels.html#level1>
>
> Return the context of the single, global Application object of the
> current process.
>
>
> public Context
> <http://developer.android.com/reference/android/content/Context.html>
> getBaseContext ()
>
> Since: API Level 1
> <http://developer.android.com/guide/appendix/api-levels.html#level1>
>
>
> Returns
>
> * the base context as set by the constructor or setBaseContext
>
> Since applicationcontext is global application object,
>
> To avoid objects retained in memory after activity is closed (assuming
> this application has lots of activities), its better to use getbasecontext
> Is my understanding right.?

Neither.

Activity is a Context.

Service is a Context.

If you need a Context, you already have one -- just use it.

Those methods are for special cases, not the normal case.

--
Mark Murphy (a Commons Guy)
http://commonsware.com | http://github.com/commonsguy
http://commonsware.com/blog | http://twitter.com/commonsguy

Android Development Wiki: http://wiki.andmob.org

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

No comments:

Post a Comment