java - Difference btn mContext.get().getApplicationContext() and getActivity() -


why in fragment getactivity() works mcontext.getapplicationcontext() not?

mdobpickerdialog = new datepickerdialog(getactivity(), new ondatesetlistener() {              public void ondateset(datepicker view, int year, int monthofyear, int dayofmonth) {                 calendar newdate = calendar.getinstance();                 newdate.set(year, monthofyear, dayofmonth);                 mdobedittext.settext(mdateformatter.format(newdate.gettime()));             }          },newcalendar.get(calendar.year), newcalendar.get(calendar.month), newcalendar.get(calendar.day_of_month)); 

my mcontext declared , initialized as:

private context mcontext;  public displayprofilefragment(context context) {         super();         mcontext = context;     } 

getactivity() returns activity fragment associated with.

http://developer.android.com/reference/android/app/fragment.html#getactivity()

getapplicationcontext() returns global application context.

http://developer.android.com/reference/android/content/context.html#getapplicationcontext()

as why getapplicationcontext() doesn't work in code have provided, because shouldn't. creating dialog on current activity, need activity context, application context should used functions receivers, functions should destroyed when application destroyed, not when activity destroyed.


Comments

Popular posts from this blog

matlab - error with cyclic autocorrelation function -

django - (fields.E300) Field defines a relation with model 'AbstractEmailUser' which is either not installed, or is abstract -

c# - What is a good .Net RefEdit control to use with ExcelDna? -