Friday, 15 July 2011

android - Is it safe to keep a reference to a ContentResolver in an AsyncTask without leaking memory? -



android - Is it safe to keep a reference to a ContentResolver in an AsyncTask without leaking memory? -

i have asynctask in i'm running database query. purpose asynctask subclass contains field of type contentresolver. i'm wondering if it's safe have or if cause memory leaks in case of context (asynctask , contexts)?

here solution, utilize static reference of application context, held application

public class myapplication extends application { private static context context; public static contentresolver getcontentresolverstatic() { homecoming context.getcontentresolver(); } @override public void oncreate() { super.oncreate(); this.context = this.getapplicationcontext(); } }

now phone call myapplication.getcontentresolverstatic() asynctask.

android memory-leaks android-asynctask android-contentresolver

No comments:

Post a Comment