Can you please tell me whats the best practice to pass activity
or context
to other instance(;)
But...,
Context
is an entity which provides global information about application or activity. You can get the context by invoking getApplicationContext()
, getContext()
, getBaseContext()
or this
(when in the activity class).
Context
is tied with lifecycle of its activity/application and commonly used for creating new objects, accessing resources e.t.c.
In your code you can use Context
as a first parameter in Toast.makeText
. It's also common to have global Context
object for a class. You may read some explanation about Context
usage here
You may need Activity object for example if you need to start new activity and create Intent
object.