how to run application in background in android?

2019-01-22 22:58发布

问题:

Hi, I want to make an Android application that continues to run in background and when user accesses any folder, picture, or any other file it notifies using toasts that he accesses this file(filename).

回答1:

You can do that by using Services in Android. Here is a nice tutorial for doing that.

Services

Also you can download a sample from my respository.



回答2:

The other people answering your question are focused on the "background" part, and a Service would indeed accomplish this. Users have fairly loudly stated that they despise constantly-running services like the one you are proposing.

when user access any folder or picture or any file it notify using tosts that he acess this file(filename).

For files that you can access yourself (e.g., those on external storage), you can use FileObserver class.



回答3:

Use FileObserver to detect file access or change.