android - how can getActivity() be used to return context in a fragment class? -


i found example code not make sense, this.getactivity() method used in code shown below. in parameters cursorloader() method, first parameter context, , this.getactivity() used here context needed. why used in example when error.

android documentation states fragment object in example, getactivity() supposed return activity object, not context object. since first parameter context, how possible use getactivity() return context when not that?

from android documentation

getactivity()

return type: final activity

return activity fragment associated with.

http://developer.android.com/reference/android/app/fragment.html

sample code

   public class yourfragment extends fragment   implements loadercallbacks<cursor> {    // more code......   public loader<cursor> oncreateloader(int id, bundle args) {   cursorloader loader = new cursorloader(      this.getactivity(), // <--- context needed here      some_content_uri,       projection,       selection,       selectionargs,       sortorder); return loader; } 

activity inherits context hence can used context

http://developer.android.com/reference/android/app/activity.html


Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -