android getContext Method -


i'm interested in getcontext() method how works, example, wrote recycle view

@override  public recycleview.viewholder oncreateviewholder(viewgroup parent ,int viewtype) { view view =layoutinflater.from(parent.getcontext()).inflate(r.layout.list_item,parent,false);} 

and call on fragment class , fragment class defined mainactivity question here how context method return mainactivity? how context understand? @ method android studio, didn't understand well

for ultimate reference: context | android developers

long story short, view class, , of it's subclasses (like viewgroup), have defined function called getcontext() returns context object. class abstract , implementation provided android system, why actual functionality not easy understand. allows access global information application's environment, such themes, resources, etc. pretty magical, magical aspect can costly if aren't careful. easy leak context object, can eat ram on device.


Comments

Popular posts from this blog

service - Android MediaPlayer calls onCompletion before it already finished -

javascript - Training Neural Network to play flappy bird with genetic algorithm - Why can't it learn? -

javascript - Create a stacked percentage column -