ibrahim yener wrote:Dear Steve
Thank you so much for this valuable information and taking your time.
Much appreciated.
So far, what did i understand is that Context holds the Activity objects and tells to another activity Where is it in the memory.
Not quite. An Activity is a Context. And a Context holds information about the application's state, access, permissions, databases, file system, assets, and things like that.
Bigger context cover more information about Application.
Depends on what you mean about 'bigger'. Broader contexts, like Application, usually have access to less information, or the same information but in a harder-to-access manner. As you get to narrower contexts like the Activity, the Context knows a bit more about what is currently happening, so it might hold more information about the specific task, or make it easier to access information more pertinent to the current activity. It is called 'narrower' because it has a shorter life span and covers a smaller range of possibilities. But it usually has access to all the information that broader contexts have.
For example, the Application context might have information about what databases are defined for the application, and what assets are available. It doesn't necessarily know about the current displayed layout. But the Activity context does know about the currently displayed layout, so it can be used to create views that are properly initialized. The Activity context usually knows all the stuff the Application does, and if it doesn't know it itself, it delegates to the Application to get it.
Using getApplicationContext for onClickListener or inner class is unnecessary isn't it?
It's more like filling bathtub for brushing teeth.
Not sure about 'necessary' or not... but most likely you want the Activity's context, because the narrower scope gives you access to what is more likely to be needed. I don't think the analogy to the excessive waste in
water is applicable - the Application context exists, has information, and you using it doesn't change its size or content. Nor does it give you access to an excess of information. It just might not be the right scope to look at... or it might be depending on needs.