Communicating with intents - Context packageContext


#1

public Intent(Context packageContext, Class<?> cls)

It says that “the Context argument tells the ActivityManager which application package the activity class can be found in”. This application package should be com.bignerdranch.android.geoquiz right? So why did the instance of QuizActivity got passed to constructor instead?


#2

The context just needs to be some context that exists in your application package. That could be any of your activities that are in memory, your application itself, or a Service.

Most Android developers use the context that is easiest to get. If this code is in an Activity, that context is the instance of the Activity (so just this).

For example, you could do this:

new Intent(this, ...)

or

new Intent(this.getApplicationContext(), ...)

They both will do exactly the same thing, but one is much less verbose than the other.