[TIMOB-18147] Android: Cannot get current activity from JavaScript broadcast receiver
GitHub Issue | n/a |
---|---|
Type | Bug |
Priority | High |
Status | Open |
Resolution | Unresolved |
Affected Version/s | Release 3.4.1, Release 4.0.0 |
Fix Version/s | n/a |
Components | Android |
Labels | n/a |
Reporter | Benjamin Hatfield |
Assignee | Unknown |
Created | 2014-12-06T00:53:10.000+0000 |
Updated | 2018-02-28T19:55:40.000+0000 |
Description
REPRODUCTION:
Run the code below in the Genymotion emulator and click the "Send Broadcast" button.
RESULTS:
Logcat reports that the current activity is a BroadcastReceiver object.
{noformat}
[INFO] : hello?
[INFO] : {"bubbleParent":true,"url":"testintent.js","apiName":"Ti.Android.BroadcastReceiver"}
[INFO] : {"bubbleParent":true,"apiName":"Ti.Android.Activity","actionBar": "bubbleParent":true,"apiName":"Ti.Android.ActionBar","title":null,"navigationMode":0,"subtitle":null}}
{noformat}
OTHER INFO:
Can get current activity using
this.Ti.Android.currentActivity
*/Resources/app.js*
var win = Ti.UI.createWindow();
var button = Ti.UI.createButton({
title : 'Send Broadcast'
});
button.addEventListener('click', function() {
var intent = Ti.Android.createBroadcastIntent({
action: 'com.appcelerator.action.ALERT'
});
Ti.Android.currentActivity.sendBroadcast(intent);
});
win.add(button);
win.open();
var broadcastReceiver = Ti.Android.createBroadcastReceiver({
url: 'testintent.js'
});
Ti.Android.registerBroadcastReceiver(broadcastReceiver, ['com.appcelerator.action.ALERT']);
*/Resources/testintent.js*
Ti.API.info('hello?');
Ti.API.info(JSON.stringify(Ti.Android.currentActivity));
Ti.API.info(JSON.stringify(this.Ti.Android.currentActivity));
[~msamah] Thoughts on priority?
[~ingo] If there's a work around "this.Ti.Android.currentActivity" and there's not many watchers on this, I think the priority shouldn't be too high. Instead, maybe a note can be added to the docs for this about broadcast receiver and on the "currentActivity" docs. Just my 2 cents.
Okay, [~bhatfield] can you put your workaround in the docs for now?