I am new to android app development. I am trying to understand what is intent and its uses.
My question is that while starting another activity, why is 'this' keyword passed as the context parameter for the intent?
Intent foo = new Intent(this, viewContacts.class);
I understand that the any activity extends Context class, but why is it that we are passing the activity context and not the application context?
My Point-
When another activity starts the current activity will get destroyed but its context will be passed to the other one. Referring to this article, it says that
The most obvious way of avoiding context related memory leak is to avoid escaping the context outside of its own scope.
So aren't we passing the context of current activity to another one where the first one goes out of scope? Isn't it an example of memory leak?
Either would work here.
thisis less typing and faster to execute than isgetApplicationContext().You are assuming that the
Intentholds onto thisContext. It does not.No.
An
Intentcan either be implicit or explicit. An explicitIntentis one that has aComponentNameattached, identifying the specific app (by package name) and Java class (by fully-qualified class name) of the component for which thisIntentis intended. The two-parameter constructor, providing theContextandClassobject, is used to build thatComponentName. Neither theIntentnor theComponentNamehold onto theContextafter the constructor work is completed.