Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to initialize context? [closed]

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.

like image 238
user2005938 Avatar asked Apr 17 '26 06:04

user2005938


1 Answers

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:

  1. Assign a pointer to an Activity object to the Context object pointer (i.e. Using the this keyword)

  2. The Activity class has a method called getApplicationContext() which retrieves a pointer to the Context object contained by the Application.

like image 142
jonbonazza Avatar answered Apr 18 '26 20:04

jonbonazza



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!