[TIMOB-19328] Android: broadcast receiver always executed twice for one broadcast
GitHub Issue | n/a |
---|---|
Type | Bug |
Priority | Medium |
Status | Reopened |
Resolution | Unresolved |
Affected Version/s | n/a |
Fix Version/s | n/a |
Components | Android |
Labels | n/a |
Reporter | Shawn Lan |
Assignee | Hieu Pham |
Created | 2015-07-31T02:25:14.000+0000 |
Updated | 2015-11-13T02:46:09.000+0000 |
Description
It was working fine. Recently I found this bug, but not sure starting which SDK version the problem existed.
Create a default Alloy project with the following:
index.xml
<Alloy>
<Window class="container" onClose="doClose" />
</Alloy>
index.js
function doClose() {
Ti.Android.unregisterBroadcastReceiver(bc);
}
$.index.open();
var onReceived = function(e) {
Ti.API.info("received!");
};
var bc = Ti.Android.createBroadcastReceiver({
onReceived : onReceived
});
Ti.Android.registerBroadcastReceiver(bc, ["android.intent.action.PHONE_STATE"]);
tiapp.xml (use the following for the android section)
<android xmlns:android="http://schemas.android.com/apk/res/android">
<manifest>
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
</manifest>
</android>
After launching the app, call to the cellphone and see the onReceived function executed twice for one broadcast.
This isn't a bug. The phone_state broadcast supposed to fire every time the phone's state changes: http://developer.android.com/reference/android/telephony/TelephonyManager.html#ACTION_PHONE_STATE_CHANGED So if you are receiving a phone call, there are multiple phone states (i.e, CALL_STATE_IDLE, CALL_STATE_OFFHOOK, and CALL_STATE_RINGING). I've also tested with android.intent.action.AIRPLANE_MODE, and it works as expected (only fired once)
For each phone state the receiver is called twice!! The bug seems to only happen with phone state. Please test using the test case under the specified environment. Please re-open this case or I'll need to create another case.
Please use the sample code to regenerate the issue. index.xml
index.js
tiapp.xml (use the following for the android section)
Let's have one more look at this.
Sorry just realised the sample code commented above is exactly the same as ticket description.
Tested this with an Emulator with Android 5.1.0 using the above code. Simulated an inbound call by running the following commands based on http://developer.android.com/tools/devices/emulator.html#telephony 1)
telnet localhost 5554
2)gsm call 1111
Broadcast receiver executed once when Picking up phone call. Broadcast receiver executed once more when phone call ended and went back to app. Unable to reproduce broadcast receiver executing twice.Have you tested on a device? I tested it on my HTC One M7. Call pickup executes twice the receiver. Call end executes twice the receiver as well.
[~shawnlan] May I know which Android version HTC One M7 is running?
5.0.2
Thanks. I'll try to test on something similar to that.