I previously had a Foreground service that I launched from one activity. The code to launch the service was contained within said activity. Now I would like to launch this service with a non-activity class that can be called from different activities. In doing this I get an error: The working code block was previously contained in the singular activity
Tag: android-context
Pass Context or make use of view.getContext(). Does it really matter?
So, I have two options to get the context. See the following two methods (cleaned up for clarity) from a Utility Class. I can pass the context or simply get it from the view. I guess I prefer the second one since it is one less parameter to pass, but I wonder if the getContext() call is costly. I’m not
Getting MainActivity context in CustomView class
I have 2 classes: MainActivity and CustomView. I have an XML layout with this CustomView. I want to access all my MainActivity variables from my CustomView class and also to modify them, I tried to get the context but it didn’t work. MainActivity class: MyCustomView class: I also tried getContext which didn’t work. Answer By trying to access variables from
Retrieve Context from a fragment
I created a class to retrieve comments from a JSON encoding from a PHP file. This class, extends from AsyncTask: As you can see, I’m trying to show a ProgressDialog while the “doInBackground” proccess is working. But progressDialog constructor, asks for a Context, and I don’t know how to provide it. I’m calling this class from a Fragment, so I