Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-18147] Android: Cannot get current activity from JavaScript broadcast receiver

GitHub Issuen/a
TypeBug
PriorityHigh
StatusOpen
ResolutionUnresolved
Affected Version/sRelease 3.4.1, Release 4.0.0
Fix Version/sn/a
ComponentsAndroid
Labelsn/a
ReporterBenjamin Hatfield
AssigneeUnknown
Created2014-12-06T00:53:10.000+0000
Updated2018-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));

Comments

  1. Ingo Muschenetz 2015-03-23

    [~msamah] Thoughts on priority?
  2. Ashraf Abu 2015-03-24

    [~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.
  3. Ingo Muschenetz 2015-03-24

    Okay, [~bhatfield] can you put your workaround in the docs for now?

JSON Source