Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

context vs views

Tags:

android

can anyone explain the difference between context and views and when do we go for context or view ? In most of the program I find either context or view being passed to certain methods , what is actual need of passing context or view to methods?

like image 239
Pravy Avatar asked May 03 '11 09:05

Pravy


1 Answers

This is a strange question. View describes one element of your ui. It can have onClickListeners, properties and so on. But every view is created in some context, usually Activity's context.

Context as itself is something like environment your code is executed in. It has access to ui(if it is an activity), it can contain some global data(application context), and has access to the resources(all of the contexts). Also, context allows you to perform common android operations like broadcasting intents, start activities and services.

So, views should be passed when you want to do something with a particular view. Context is passed when you need access to resources, global data or ui context, or launch other android components.

like image 198
Vladimir Ivanov Avatar answered Oct 12 '22 15:10

Vladimir Ivanov