Skip to content

Tag: service

How to access a variable of a service from an activity

I understand that in order to access methods of a service from an activity, we should bind the service. But if we just want to get the value of a variable in the service, can we just access it like so without binding? It works, but I’m not sure if it has any memory leak implications or any other issues.

Using Intent.createChooser and getting error: Calling startActivity() from outside of an Activity context requires the FLAG_ACTIVITY_NEW_TASK flag

I want to open the share via option from the service class. It is working fine in Android 7, but in 8+ OS it starts showing android.util.AndroidRuntimeException: Calling startActivity() from outside of an Activity context requires the FLAG_ACTIVITY_NEW_TASK flag. Is this really what you want? I have also incl…

Can’t use FileObserver to Observe Files Inside a Folder

I want to observe if any file/folder is added inside /storage/emulated/0/DCIM/Camera using FileObserver in a service, but it didn’t work. Please tell me if there is anything wrong in my code 🙏. Here is the source code: AndroidManifest.xml I added the uses-permission and service tags: LogWatcherService.j…