Closed molsen-ee closed 8 years ago
Hi @molsen-ee Thanks for reporting this. I'll test this asap. Does this happen with the latest version of the module?
Yes, I was able to reproduce this bug with version 1.6.7 of the module.
Have you tried using the window property?
The window property of the abx object? I don't follow what you are asking.
Sorry, I'm not on a computer right now. But yes, abx has a window property which allows you to define a window reference. When you open multiple instances of a window, it could be a good idea to make use of this property. That way you can make sure that abx uses the actionbar according to the correct window. By default it uses the current window which is open. This could lead into timing issues. If it references a window that is not yet open or not open anymore the actionbar reference may be null. Thus there occur a NullPointerException. This is indeed just a guess but I'll test this tomorrow and let you know. I think there is a simple way to fix this.
Ah hah! That gave me just enough insight to get around the timing issue. In the controller logic I was creating the abx
javascript variable via requre
and setting the abx.window
property. However in the focus
event handler I was not setting the abx.window
property to the current window so at the Java level it was still referencing a window that had been opened later in the logic flow.
Simplified version of my code:
var abx = require('com.alcoapps.actionbarextras');
abx.window = $.thisWindow;
$.thisWindow.addEventListener('focus', function(e) {
abx.window = $.thisWindow; // adding this line solved the problem!
if (useDifferentIcon())
abx.setHomeAsUpIcon("/images/differentIcon.png");
else
abx.setHomeAsUpIcon("/images/defaultIcon.png");
});
Hm, this NullPointerException should get catched here
@molsen-ee Can we close this issue?
I was confused about the stack trace's line numbering as well. Is the 1.6.7 jar built on the current code?
Yes, the change in logic is working for me. Thank you for the help.
If a window has a 'focus' event that tries to call the
abx.setHomeAsUpIcon()
function there will be a Java NullPointer exceptionSteps to reproduce: 1) Create a window that uses actionbarextras (abx) 2) add an eventListener('focus') that calls abx.setHomeAsUpIcon() 3) Have functionality that allows this window to be opened multiple times (such as a label with an onClick event) 4) After opening this window multiple times, press the Android "back" button at least twice 5) The second "back", when calling the 'focus' event, will throw the following exception (stack trace truncated):