This is a really stupid question but what do I set context equal to in Context context = ...
Just declaring it sets it to null and I need to use context for my app.
You cannot instantiate a Context object. This is controlled by the system. However, every Application has a Context and every Activity is a Context, so you have a couple of was to obtain a pointer to a Context object:
Assign a pointer to an Activity object to the Context object pointer (i.e. Using the this keyword)
The Activity class has a method called getApplicationContext() which retrieves a pointer to the Context object contained by the Application.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With