简体   繁体   English

重新打开appcelerator应用程序崩溃

[英]Reopening appcelerator app crashes

I'm building a small app in Appcelerator and in my index.js I've created 3 tabs and opened them in a Tabgroup, pretty basic stuff. 我正在Appcelerator中构建一个小型应用程序,并在index.js中创建了3个选项卡,并在一个Tabgroup中打开了它们,这是非常基本的东西。

See my code below: 请参阅下面的代码:

var win1 = Alloy.createController('getContacts').getView();
var win2 = Alloy.createController('getGroups').getView();
var win3 = Alloy.createController('settings').getView();

var tab1 = Ti.UI.createTab({
    window: win1,
    icon:'KS_all.png',
    backgroundSelectedColor:'#ffffff'
}),
tab2 = Ti.UI.createTab({
    window: win2,
    icon:'KS_groups.png',
    backgroundSelectedColor:'#ffffff'
}),
tab3 = Ti.UI.createTab({
    window: win3,
    icon:'KS_settings.png',
    backgroundSelectedColor:'#ffffff'
}),
tabGroup = Ti.UI.createTabGroup({
    tabs: [tab1, tab2, tab3],
    tabsBackgroundColor:'#ff6600',
    tabsBackgroundSelectedColor:'#ffffff',
    exitOnClose:'true'
});

tabGroup.open();

Everything seems to be working fine when installing the app on my phone, switching between tabs/windows are working as they should and events/functions within my windows firing properly. 在手机上安装应用程序,在选项卡/窗口之间进行应有的切换以及窗口内的事件/功能正常启动时,一切似乎都正常运行。

The problem start when I close the app, when one of my tab windows is openend and I press the android back button. 当我关闭应用程序时,问题开始,当我的其中一个标签窗口打开时,我按下了android后退按钮。 The app shuts down but when I reopen the app it results in an alert message popping up saying the app has stopped working. 该应用程序已关闭,但是当我重新打开该应用程序时,会弹出一条警告消息,提示该应用程序已停止运行。

I can't seem to find whats wrong with my code, could it be that it's phone (HTC M8) or Appcelerator related? 我似乎找不到我的代码有什么问题,可能是电话(HTC M8)或与Appcelerator相关的吗?

EDIT 编辑

I've tested the suggested methods by Soumya and Fokke, which resulted in my app not crashing. 我已经测试了Soumya和Fokke提出的建议方法,这导致我的应用程序没有崩溃。 It also closes and continues as it should on restart. 它也将关闭并继续,应在重新启动时继续。 I've changed declaring win1, win2 and win3 from using the createController to createWindow like so: 我已经更改了从使用createController到createWindow的声明win1,win2和win3的方式,如下所示:

var win1 = Ti.UI.createWindow({backgroundColor:'red', title:'Contacts'});
var win2 = Ti.UI.createWindow({backgroundColor:'green', title:'Groups'});
var win3 = Ti.UI.createWindow({backgroundColor:'blue', title:'Settings'});

And changed the exitOnClose in my createTabGroup from a string to a boolean (I'm deeply sorry Fokke). 并将我的createTabGroup中的exitOnClose从字符串更改为布尔值(对不起,Fokke非常抱歉)。 This seems to work perfectly. 这似乎完美地工作。 Great, now I can continue building my app. 太好了,现在我可以继续构建我的应用了。 But how am I able to use the code (parsing json data) from my js files I wanted to use as windows? 但是,如何使用我想用作Windows的js文件中的代码(解析json数据)呢?

Copying the code from my files (getContacts.js, getGroups.js and settings.js) into the index.js shouldn't be the solution, right? 将代码从我的文件(getContacts.js,getGroups.js和settings.js)复制到index.js应该不是解决方案,对吗?

In the documentation link, there is a sample code. 在文档链接中,有一个示例代码。 Can you try to run the code and see if that works out for you. 您可以尝试运行代码,看看是否对您有用。

http://docs.appcelerator.com/platform/latest/#!/api/Titanium.UI.TabGroup-method-close http://docs.appcelerator.com/platform/latest/#!/api/Titanium.UI.TabGroup-method-close

The next step is to createWindow and assign it to win1, win2 and win3, instead of doing createController. 下一步是createWindow并将其分配给win1,win2和win3,而不是执行createController。

Can you confirm the above two scenarios work fine. 您能否确认以上两种情况都能正常工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM