Problem Description
On Android (2.3, but reports of 2.2 also), using SDK 1.8+, OptionDialog behaviour seems to be erratic.
There seems to be two separate issues:
Dialogs on our main screen open fine one first load, repeated opening and closing, however once you navigate away from that window, when you return, the dialogs no longer display
App wide events which display dialogs open fine once, but sometimes not subsequently
Some code to replicate issue 1 is below. This bug occurs on both device and emulator. This does not occur with SDK < 1.8
Actual results
option dialog not showing, and you get this in the log:
W/TiUIDialog( 386): (main) [2,8442] dialog activity is destroyed, unable to show dialog with message: null
Expected Results
The option dialog showing always
Test case
Open app
Click "Open dialog", dialog opens
Close dialog
Click "Open window", window 2 opens
Go back to window 1
Click "Open dialog", dialog does not open
If dialog opens, repeat steps 3-6 multiple times, dialog will fail within 2-3 repeats
var win1 = Titanium.UI.createWindow({
title:'Window 1',
backgroundColor:'#fff'
});
var button1 = Titanium.UI.createButton({
title: 'Open window',
top: 30
})
var button2 = Titanium.UI.createButton({
title: 'Open dialog',
top: 80
})
button1.addEventListener('click',function(){
var win2 = Titanium.UI.createWindow({
backgroundColor: '#fff',
modal: true,
title: 'Window 2'
})
win2.open()
});
button2.addEventListener('click',function(){
var optionDialog = Titanium.UI.createOptionDialog({
buttonNames: ['Ok'],
title: 'Dialog'
})
optionDialog.show()
});
win1.add(button1);
win1.add(button2);
win1.open();
I should have added this is related to this Q&A post: [http://developer.appcelerator.com/question/131734/android-23-optiondialog-issues]
I had your problem, try not to use local variable when createOptionDialog on android. Try use global variable as you can see on the Kitchen Sink example of Option Dialog
The fix for timob-7024 fixes this problem. Here's the PR link: https://github.com/appcelerator/titanium_mobile/pull/2324 We will backport this fix to 2.0.X.
Closing ticket as duplicate of the ticket that is mentioned above and has since been closed.