Can an Android app run before the user launches it?

The application has a BroadcastReceiver that listens for the event with the completion of the download and runs a background service to send some data to my HTTP server.

My question is: if the application is never started by the user (installed only), will BroadcastReceiver receive a download event?

+6
source share
2 answers

Starting with the android 3.1 user, the user must run the application once so that he receives the boot_complete transmission.

Following is the official javadoc:

Starting with Android 3.1, the system package manager monitors applications in a stopped state and controls their launch from background processes and other applications.

Please note that the application stopped state does not match the activity stopped. The system manages these two stopped states separately.

The platform defines two new flags of intent, which allow the sender to indicate whether the Intent should be allowed to activate the components in the stopped state of the application.

FLAG_INCLUDE_STOPPED_PACKAGES - Enable application intent filters in the list of potential goals for the solution. FLAG_EXCLUDE_STOPPED_PACKAGES - exclude filters of intent to terminate applications from the list of potential goals. When neither or both of these flags are determined in intent, the default behavior is to include filters for stopped applications in the list of potential targets.

Please note that the system adds FLAG_EXCLUDE_STOPPED_PACKAGES to all broadcasts. It does this to prevent broadcasts from the background of services from unintentionally or unnecessary component launches of stopped applications. The background service or application can override this behavior by adding the FLAG_INCLUDE_STOPPED_PACKAGES flag to broadcast intentions that must be allowed to activate the application.

Applications are in a stopped state when they are first installed, but not yet launched and when they are manually stopped by the user (in the "Application Management" section).

javadoc link

Read More This Blog For More Details

+4
source

Yes, the boot receiver is registered to listen to the download, so if you reboot your device, it will work, regardless of whether the application is running or not. Similarly, if you add NFC listeners to your manifest, then if someone checks the NFC card, the application will respond. The manifest is used by Android to respond to everything you specify in it. It does not depend on whether the application is running (or has ever been executed). Great question though! :)

EDIT according to other answers and documentation. This is no longer the case. Sorry for the confusion.

+1
source

Source: https://habr.com/ru/post/945037/


All Articles