You don't need to set the Context
. An Intent
doesn't need a Context
. You only need to pass a Context
in the particular variants of the constructor that also take a Class
parameter (there are several available constructors):
Intent(Context packageContext, Class<?> cls)
Intent(String action, Uri uri, Context packageContext, Class<?> cls)
The reason that you need to pass a Context
here is that the constructor uses the Context
and Class
parameters to set the Component
in the Intent
. To set the Component
, the constructor needs to have the package name and the class name (both are of type String
). It can get the class name from the Class
parameter, and it uses the Context
to get the package name.
You have several alternatives. You can use an empty Intent
constructor and set the Component
later using any of these methods:
setClassName (String packageName, String className)
setClassName (Context packageContext, String className)
setClass (Context packageContext, Class<?> cls)
setComponent (ComponentName component);