Reputation: 314
My broadcast receiver does not work when the application is not running in the background.
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme.NoActionBar" >
<receiver android:name=".network.NetworkChangeReceiver"
android:enabled="true">
<intent-filter>
<action android:name="android.net.conn.CONNECTIVITY_CHANGE" />
</intent-filter>
</receiver>
<activity
android:name=".view.activity.MainActivity"
android:label="@string/app_name">
</activity>
<activity android:name=".view.activity.BarLoginActivity"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
My receiver works fine when the app is running in the background but as soon as I remove my recent apps it does not work. Running on API 19
Upvotes: 0
Views: 1665
Reputation: 314
Finally it worked in other android phones. as broadcast receivers and services are by default not allowed in Xiaomi phones
Upvotes: 3
Reputation: 12587
Haven't seen your entire AndroidManifest
but my first suspect is that you're lacking the proper permission.
In order to listen to network changes you must declare that you are using this permission in the manifest like this
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
the next suspect is the name you gave, maybe try giving the full path to the reciever name
Upvotes: 1
Reputation: 294
I would try putting a android:process=":remote" in the Manifest definition of the receiver so that it will run on a separate task.
Upvotes: 1