Quantcast
Channel: Appcelerator Developer Center Q&A Unanswered Questions 20
Viewing all articles
Browse latest Browse all 8068

Best practice when navigating between windows in Alloy?

$
0
0

Hi

I finally found out how to use a background image that does not stretch on the various iOS screens (see how) - and with the help of Malcolm Hollingsworth I found an even better way to set a background image for the entire application!

One problem I experience, though, is when changing from one window to another - the old contents stay. I have found a workaround (by trial and error) - but I am not sure if this is best practice.

This is a simple example:

index.xml

<Alloy>
    <Window>
        <Label>Hello, World</Label>
        <Button onClick="doGoNext">Go Next</Button>
    </Window>
</Alloy>
next.xml
<Alloy>
    <Window id="next">
        <Label>I am NEXT!!</Label>
        <Button onClick="doGoBack">Go Back</Button>
    </Window>
</Alloy>
index.js
var doGoNext = function(e) {
    $.index.close();
    $.index = null;
    var appWin = Alloy.createController("next").getView().open();
};
// Set background for entire app
Ti.UI.setBackgroundImage("/background.png");
$.index.open();
next.js
var doGoBack = function(e) {
    $.next.close();
    $.next = null;
    var appWin = Alloy.createController("index").getView().open();
};
And some simple styling for the entire app:

app.tss

"Window": {
    statusBarStyle: Ti.UI.iPhone.StatusBar.LIGHT_CONTENT,
    backgroundColor: 'transparent'
}
"Button": {bottom:"50dp"}
If I do not close the current window and set it to null before I open the new window then it will just get painted on the existing window (this is easy to see by commenting out the two lines in doGoNext and doGoBack). If I just close it (but don't set it to null) I will get an error message when going back to the same window again. I have also read/heard that I need to be aware of memory leaks in window handling - so this is my guess on how to do that.

Any comments and suggestions on the above would be greatly appreciated :-)


Viewing all articles
Browse latest Browse all 8068

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>