What is the proper way of opening, closing and reopening a window. I currently have it as below:
app.js
win.open();
win.jswin.close();
Called again in app.jswin.open();When the window is opened the 2nd time, I run into all kinds of errors. Mainly, none of the buttons respond.
3 Answers
when you called win.close(); I believe the framework attempts to clean up things and that is why you are seeing bizarre behavior.
what I usually do is just have a function that creates the window, and it checks to see if window is null before executing.
I am assuming this behavior based on this from the documentation
Optimizations UI objects are optimized by Titanium to not be realized into the drawing context and placed into the device UI surface until needed. That means that you can create UI objects, set their properties and add them to their hierarchy without much worry about memory or performance. When the native drawing surface needs to render a specific view or control, Titanium will automatically create the view as needed. Additionally, Titanium is optimized to also release memory once the view is no longer needed, on screen or in low memory situations. However, it's a good idea to help Titanium along in certain cases where you are no longer using objects. For example, you should call close on a Window instance when you are no longer using it. You can safely call open on the Window again to re-open it.
If I understand well from your last comment, you have a window win1 that presents some information and opens another window win2, where you perform some task that affect the information in win1: when you close win2, data in win1 must be changed accordingly.
If my reconstruction is right, you might set up a custom event listener in win1 and fire a synthesized event in win2, just before closing it. In the event handler you simply update the presented data.
I also experienced the same problem with the 'focus' event not being fired on Android, so I came up with this fallback solution that worked for me.
The body of my program is using scrollview, when I open my win2 the 2nd time, I can scroll the body and see a duplicate of the information behind it. It does seem that the window is never fully closing. Perhaps I could run a while loop to close all instances? How do I check if a window is open (without setting a variable as a bool because I beleive the bool will get changed but the window will not have actually closed...)
Your Answer
Think you can help? Login to answer this question!