I'm developing an app in Titanium that needs to work on android and IOS, but I'm getting some memory problems.
In my app.js file I have this:
var win = Ti.UI.createWindow({
backgroundColor : 'white',
url : 'Home.js'
});
win.open();
Ti.App.View = [];
The Ti.App.View array is tu keep a reference to all my container views along my project so I can close them or check if they are already visible.
Then in my Home.js file I have some buttons to open some views. Ex:
var view = Ti.UI.createView({
height : deviceHeight,
width : deviceWidth,
backgroundColor : 'white'
});
Ti.UI.currentWindow.add(view);
var viewMenu = Ti.UI.createView({
layout : 'vertical',
width : deviceWidth * 0.20,
backgroundColor : 'transparent',
});
view.add(viewMenu);
viewMenu.addEventListener('click', function() {
var Favorites = require("Eventos");
Events.AddLayout();
});
This is the way how I add a new layout to the same window.
Then on my Events.js file I have a function like this and a global event :
exports.AddLayout = function(e) {
//adding all my layout.....
}
Ti.App.addEventListener('Update', function() {
// due something in hear
});
My question is how can I remove all Ti.UI objects created in the AddLayout function from memory when I press back button? And how can I remove the global event created by the Events.js file?
I have tried to reference te container view to null but it has not solved my problem.
Have you considered developing this with Alloy? It uses a commonJS approach and would remove the need to use Global events like this and structure the app in a way that's easier to represent views, open and destroy views etc.
If not, try to avoid using Global Event listeners -- typically there's no need to use these and they'll end up causing all kinds of memory leaks.
This is a great video on the subject:
Your Apps Are Leaking
Hope this helps!
Related
My engironment is titanim 6.0.1.GA
It doesn't show the label on Android, while iOS show the label correctly.
var descriptionView = Ti.UI.createView({
height:'100%',width:'100%'
children:[Ti.UI.createLabel({
wordWrap :true,top:0,
color:'black',
text:"my label",
})]
});
It works well both on Android/iOS
var descriptionView = Ti.UI.createView({
height:'100%',width:'100%'
});
var label = Ti.UI.createLabel({
wordWrap :true,top:0,
color:'black',
text:"my label",
});
descriptionView.add(label)
I just wonder using children is bad behaivor for andorid?
However it sometimes very useful to simplify the code.
Is there anyone who uses children successfully for Android??
According to the titanium API 'Children' property is a read only property and it should not be used to set data. It's considered to be good luck as it's working with IOS but with Android we need to be specific with the code.
I would never suggest you to use this coding style to simplify the code, rather you could use the following to simplify and also memory effective way :
var descriptionView = Ti.UI.createView({
height:'100%',width:'100%'
});
descriptionView.add(Ti.UI.createLabel({
wordWrap :true,top:0,
color:'black',
text:"my label",
}));
Good luck,
Cheers
I use the VerticalDownSwipeJump when rendering a new scene in my React Native project. New scenes are supposed to come into view from above, pushing the current scene out of view.
On iOS this works as expected, on Android however the new scene being rendered comes into view from the above AND the right side as well.
Not sure why this is the case on android and not on iOS...
I haven't found any reports of this issue on SO or the React Native Github.
Any clues why this is happening?
This is quite old question, but maybe somebody will have the same problem. First of all, You can customize this view. The animations are defined here:
node_modules/react-native/Libraries/CustomComponents/Navigator/NavigatorSceneConfig.js
Below steps which I have made:
1.
I've created my own object:
var FromTheRightCustom = {
opacity: {
value: 1.0,
type: 'constant',
},
scaleX: {
value: 1,
type: 'constant',
},
scaleY: {
value: 1,
type: 'constant',
},
};
I've replaced FromTheRight to FromTheRightCustom in two places:
i)
var FromTheDown = {
...FromTheRightCustom,
ii)
var FromTheTop = {
...FromTheRightCustom,
The only difference, that in Android you will have empty space made by StatusBar. This can be fix e.g. by backgroundColor of navigator (sceneStyle).
I need to get current window in the tabbed application.
I tried with
var win = Ti.UI.currentTab.window();
and with
var win = Ti.UI.currentWindow;
but get the Uncaught TypeError: Cannot call method 'window' of undefined error in both cases.
If you are using TabGroup, you can access current window through activeTab property. It's not global function, so you have to have keep reference to TabGroup object in your code:
var tabGroup = Ti.UI.createTabGroup({ tabs: createTabs() });
tabGroup.activeTab.window
currentTab and currentWindow are holdovers from when you could spin off multiple JavaScript contexts from a Ti.UI.createWindow({ url: 'foo.js' }). I'd recommend you don't use them.
There are a couple of patterns to choose from when you need to communicate from one part of your app to the UI at another part.
1st option: listen for and fire events a la Ti.App.addEventListener('foo', function(data){}) and Ti.App.fireEvent('foo', { }). This decouples the code nicely, so you can move the UI handling code around without changing the firing code.
2nd option: expose the UI objects through modules. In your controller, exports.win = $.win;.
3rd option: set a global object: Alloy.Globals.win = $.win;.
ok so in alloy framework, we just use $ sign to get all the controls which are created in .xml file...
so if you set id of your window tag in .xml file then you can get current window with below example...
.xml file
<Alloy>
<Window id="win">
</Window>
</Alloy>
.js file
var win = $.win
so from above code you can get your current window.
Hope you get it.
I'm working on Titanium 2.1.3 and deploying for both iOS and Android.
I'm having trouble displaying images on ImageView on Android in a TableView, if I do something like clicking on the search bar and show the keyboard then the images are shown or if I scroll the TableView the images appear and disappear with no apparent reason. It seems that unless I do something that forces a layout refresh on the TableView, the images aren't rendered.
The images are being loaded the same way in both Android and iOS, which is like this:
var itemIconHolder = Titanium.UI.createView({
width : '100dp',
left : '55dp',
height : "100%"
});
var itemIcon = Titanium.UI.createImageView({
left : '0dp',
height : '100%',
});
var f = Titanium.Filesystem.getFile(Titanium.Filesystem.applicationDataDirectory, "thumb-" + filename);
itemIcon.image = f;
itemIconHolder.add(itemIcon);
This problem doesn't happen in iOS, on iOS devices/simulator the behaviour is normal and flawless, but on Android devices/emulator it happens.
Do I have to load the images differently in Android? Am I missing something? I hope someone could help me in this one.
Thanks in advance.
EDIT
I tried these approaches:
itemIcon.image = f.read();
and
itemIcon.image = Titanium.Filesystem.getFile(Titanium.Filesystem.applicationDataDirectory, "thumb-" + filename);
but the images still aren't rendered until I make something that causes the TableView to refresh in some way.
I found a workaround for this particular issue on Android.
Since it takes a layout refresh for the images to be rendered properly, what I did was to animate the table, moving it 1dp in a direction and at the completition of said animation I animated it again to return it to its original position. This is the code I used:
var table_bottom = '-1dp'
var tableAnimation = Ti.UI.createAnimation({
bottom : table_bottom,
duration : 100
});
tableAnimation.addEventListener('complete', function(e){
var table_bottom = '50dp';
if (osname === 'android')
{
table_bottom = '0dp'
}
table.animate({
bottom : table_bottom,
duration : 100
});
});
I've encountered this kind of problem with both Titanium SDK 2.1.3 and Titanium 3.0.
I making application for Android and ipone using titanium sdk in which i have used tabgroup.but when i go from one one screen to another screen in same tab.tab is dissable in second screen while it is visible i iphone device not in Android device.
I have used fiollwing codeto go from main window to inner window in same tab.
**
Continue.addEventListener('click',function(e)
{
var win = Titanium.UI.createWindow({
url:'tab1_continue.js',backgroundColor:'#fff'
});
Titanium.UI.currentTab.open(win,{animated:true});**
it does not work on android.plz help
The "url" property is causing the window to be heavyweight, which means it cannot be a child of the tab group (it necessarily takes up everything). Read more on the discussion in the Appcelerator Q&A about this topic.
if this is in "app.js" then use this code
Continue.addEventListener('click',function(e){
var win = Titanium.UI.createWindow({
url:'tab1_continue.js',backgroundColor:'#fff'
});
<tabName>.open(win,{animated:true});**
});
otherwise
Continue.addEventListener('click',function(e){
var win = Titanium.UI.createWindow({
url:'tab1_continue.js',backgroundColor:'#fff'
});
Titanium.UI.currentTab.open(win,{animated:true});
});