David McEleney David McEleney - 1 year ago 84
Android Question

BroadcastReceiver works for a while, then stops

I'm developing an android app that responds to incoming calls. I've set up a broadcast receiver, set the permission and intent filter in the manifest file, and a lot of the time, it works. I can kill all apps, reboot the phone and it still works..

However, sometimes it doesn't react, and after this happens once, it doesn't respond after a reboot either.

I've been struggling with this for about a month and it's driving me bananas. I really need my app to respond every time an incoming call is received.

I've tried trimming out all code, and just displaying a Toast message when a call is received or ends. Even when the app does nothing else but this, the behaviour is still the same.

I can't replicate this on an emulator, I'm using my HUAWEI ASCEND Y550 to device test.

Any help is hugely appreciated,



<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.test.app.receivertest" >

<uses-permission android:name="android.permission.READ_PHONE_STATE" />

android:theme="@style/AppTheme" >
android:label="@string/app_name" >
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
<receiver android:name=".CallReceiver" android:enabled="true">
<action android:name="android.intent.action.PHONE_STATE" />

My Receiver:

public class CallReceiver extends BroadcastReceiver {

public void onReceive(Context context, Intent intent) {
try {
if (context == null && intent == null)

String state = intent.getStringExtra(TelephonyManager.EXTRA_STATE);

String action = intent.getAction();
Toast.makeText(context, action + " " + state, Toast.LENGTH_SHORT).show();
} catch (Exception ex) {
try {
Toast.makeText(context, "Error", Toast.LENGTH_SHORT).show();
catch (Exception e)

Answer Source

I think I may have solved this - although I'm new to developing and even using android phones...

In my HUAWEI phone, I have an option in my settings for "Protected Apps" - those which won't get killed.

I've had a look at a few friends android phones and have been unable to locate the same settings - So am I right to say it's a HUAWEI specific feature that compensates for a poor battery.

Can anyone confirm this is a HUAWEI specific issue?


Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download