Can I still receive broadcast receiver intent after I force stopped my app on android?

A simple question. Does it happens that I still receive the registered broadcast receivers after I force stopped the application?

Answers


if your receivers are registered in AndroidManifest then yes, your app will still receive it. On the other hand, if you are registering via code (in service/activity), then the app won't receive it


Does it happens that I still receive the registered broadcast receivers after I force stopped the application?

On Android 3.1+, no. Once the user has force-stopped your application, you will receive no more broadcast Intents, of any kind, until the user manually starts one of your activities.


You shouldn’t add FLAG_INCLUDE_STOPPED_PACKAGES to your receiver's intent that start your activity or service. You have to add it to the intent that you use for sendBroadcast. Meaning, you need to add it to the intent in the application that invokes the Broadcast.

This is how you should trigger your receiver from another application:

      Intent intent = new Intent("com.xxx.my_filter_intent");
      intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);
      this.sendBroadcast(intent);

If you have no control on this broadcast (for example if it is a system broadcast) and there is no such flag inside - then your app will not be triggered by this broadcast if it is in force stop state.

Read more here: http://developer.android.com/about/versions/android-3.1.html#launchcontrols


use my method if you want to start a hidden app for just first time I make a transparent Launcher activity like this

<activity android:name=".MainActivity"
android:label="@string/app_name"
android:theme="@style/Theme.Transparent"
android:excludeFromRecents="true"
>
<intent-filter>
    <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
</intent-filter>

So I make the app hidden in launcher by placing this code in oncreat()

PackageManager p = getPackageManager();
ComponentName componentName = new ComponentName(this, MainActivity.class);
p.setComponentEnabledSetting(componentName,PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);

So I use this code for show app icon on launcher and make it run able on service class that use broadcast receiver boot and in network connection broadcast receiver class too(autostart.java and networkConnectinCheck.java):

PackageManager p = context.getPackageManager();
ComponentName componentName = new ComponentName(context, MainActivity.class);
p.setComponentEnabledSetting(componentName, PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP);

Now I can run app for first time by user hands and after this I use my receiver's to lunch app any time.


Need Your Help

Why use named function expressions?

javascript function anonymous-function function-expression

We have two different way for doing function expression in JavaScript:

python - how to check if matrix is sparse or not

python class matrix sparse-matrix

I have a matrix and I want to check if it is sparse or not.