-2

For the Intent constructor -

Intent(Context context, Class myClass)

what exactly does the context argument specify ?

Also, do we ever need to set it to the context of any other application ?

Cygnus
  • 3,040
  • 8
  • 33
  • 59

1 Answers1

2

According to the Context documentation:

Interface to global information about an application environment. This is an abstract class whose implementation is provided by the Android system. It allows access to application-specific resources and classes, as well as up-calls for application-level operations such as launching activities, broadcasting and receiving intents, etc.

Or in other words it is a class that provides access to your application.

Also, do we ever need to set it to the context of any other application ?

No, the context of your applciation is provided by Android.

Normally, for 'normal' applications you do not need to bother with the context. Unless you need to activate your application from another application or send a message between two running applications.

If you want to launch an application you do not need its context though, as you normally do not have the context of another application. Instead, you can ask Android for it (using the application name), in the form on an Intent:

Intent LaunchIntent = getPackageManager().getLaunchIntentForPackage("com.package.address");
startActivity(LaunchIntent);

See Launch an application from another application on Android for more information.

Community
  • 1
  • 1
Veger
  • 34,172
  • 10
  • 101
  • 111
  • So if i use startActivity for starting the activity of any other application, what would be the context argument in that case for the Intent i use ? – Cygnus Apr 05 '13 at 07:35