guy777
guy777

Reputation: 29

Android - What are exactly are you passing to the constructor of an intent when creating an explicit intent

When you are creating an explicit intent in android you pass a packageContext object and a Class object. For the packageContext what I found out is that you pass "this" which is a reference to the current object calling the method so that the intent knows that it is being passed from that class, assuming you did't insert "this" what changes would that have on the intent and why is it also not a Class object like the second one and a packageContect object instead and what exactly is a packageContext and Class object?

Upvotes: 0

Views: 122

Answers (1)

Rishabh Ritweek
Rishabh Ritweek

Reputation: 620

"this" only represents the object of a class which has inherited Context class. You cannot use this everywhere while creating an explicit intent object. For e.g. inside an anonymous class, while creating an explicit intent, you wouldn't use "this". If you have to create an intent for a specific component like activity or a service, you got to pass the context object else, its not required and you may use other possible constructor.e.g. of the specific component include an activity where your intent would take you or a service which you specifically wanna start.

Packagecontext: A Context of the application package implementing this class. Context : Interface to global information about an application environment

Upvotes: 1

Related Questions