A simple question. Does it happens that I still receive the registered broadcast receivers after I force stopped the application?
4 Answers
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.

- 986,068
- 189
- 2,389
- 2,491
-
3@MikeT: Having the user manually start one of your activities *is* the "workaround". – CommonsWare Jun 01 '12 at 12:47
-
Ok, good to know! But why? To give the user more control over the apps? Also, I am wondering: do these taskmanager apps also call this force-stop when freeing memory? Or do they use less intrusive ways to kill a process? – Peterdk Jun 22 '13 at 12:29
-
1@Peterdk: "But why? To give the user more control over the apps?" -- presumably, yes. "do these taskmanager apps also call this force-stop when freeing memory?" -- third-party ones cannot, as they lack permission (unless installed as a system app by rooted device users). Task managers that ship with the device could force-stop apps, and in some cases do. – CommonsWare Jun 22 '13 at 13:27
-
@MikeT Another potential "workaround" would be to use a bound-service. – Steven Mark Ford Jul 01 '15 at 10:36
-
@CommonsWare but sir, device system app steel receive the system broadcast. I have proof about that, I develop this application.so please sir explain me why this different in both app. – Zala Janaksinh Sep 17 '15 at 05:07
-
@CommonsWare system/pri-app/xyz.apk I force stop this application by settings but those app steel receive the system broadcast like NetworkStateChange,BootReceiver, etc...So sir please guide me what the actual different between them..!!! – Zala Janaksinh Sep 17 '15 at 05:51
-
look at @udi-reshef 's answer – aliep Mar 11 '21 at 17:29
-
@zero.zero.seven: Thanks! I put [a comment there](https://stackoverflow.com/users/115145/commonsware). There are relatively few scenarios where you would be both the sender and the receiver of the broadcast. – CommonsWare Mar 11 '21 at 19:15
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

- 1,083
- 1
- 11
- 14
-
Note that this only matters if you are the one both sending and receiving the broadcast. – CommonsWare Mar 11 '21 at 17:43
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.

- 9
- 5
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

- 67,549
- 16
- 165
- 178
-
3This no longer appears to be the case as of 3.1. See @CommonsWare's answer below. – Lorne Laliberte Dec 04 '12 at 17:45
-
@ZalaJanaksinh it wasn't "foolish" the time it was answered - only if you know the android history :) – waqaslam Sep 17 '15 at 10:55
-
@waqaslam I am agree with you,But now is not working , I just want to update this. – Zala Janaksinh Sep 17 '15 at 10:57
-
@waqaslam - All the services and the notifications are stopped in many devices when I force close the application. Is there any alternative? I am trying t implement push notifications and I am stuck here. – Sahana Prabhakar Jan 17 '17 at 11:10