Lai Yu-Hsuan Lai Yu-Hsuan - 11 months ago 131
Android Question

What's packageContext in Intent#(Context packageContext, Class<?> cls)?

The document says :


packageContext A Context of the
application package implementing this
class.


But what does it mean? which class is "this class"?

Why
new Intent(this,XXX.class)
works?

Flo Flo
Answer Source

You can pass any Context object you got from any of you application's classes. So you can either use an Activity, Service object or you can call getApplicationContext() and pass the returned Context object to the Intent constructor.