What I think I would recommend is not using digium.background(), but instead clear all the controls from the main window and then show your group that contains all the widgets you have set for your main screen.
So assuming you’ve setup group to have all your main window widgets you can do something like this in the processSubmit callback on the genericForm object parameter:
window.clear();
window.add(group);
Which will then just paint all your main window widgets back into the main window and there shouldn’t be any flickering.
A modified version of the genericFormExample showing this would be:
var util = require('util');
var app = require('app');
var screen = require('screen');
app.init();
var group = new Group(0, 0, window.w, window.h);
group.add(new Text(0,0,window.w, window.h, "This is the mock main window.\nPress any key to show the form again"));
var genericForm = require('genericForm');
var form_items = [
{
'text' : 'Extension number',
'setting' : 'extension',
'inputType' : 'numeric',
'validate' : '[0-9][0-9][0-9]',
'errorMsg' : 'Extension must be 3 digits in length',
'inputParams' : {}
},
{
'text' : 'Password',
'setting' : 'password',
'inputType' : 'numeric',
'validate' : '[0-9]+',
'errorMsg' : 'Password must contain only digits',
'inputParams' : {}
}
];
var form_params = {
'id' : 'exampleForm',
'labelWidth' : (digium.phoneModel === 'D70') ? 140 : 125,
'values' : {
'extension' : '123',
'password' : ''
},
'inputs' : form_items,
'object' : {
processBack : function() {
util.debug("Back pressed.");
digium.background();
},
processSubmit : function() {
util.debug("Submitted presssed.");
for (var i = 0; i < form_items.length; i++) {
var setting = form_items[i].setting;
util.debug(setting + " : " + genericForm.getValue({'setting' : setting}));
}
window.clear();
window.add(group);
}
},
'title' : 'Extension Login',
'onkeyline1' : digium.background,
'onkeycancel' : digium.background,
'forceRedraw' : true
};
digium.event.observe({
'eventName' : 'digium.app.foreground',
'callback' : function () {
genericForm.show(form_params);
}
});
window.onkey = function(evt) {
genericForm.show(form_params);
};
Does this work for you?