appcelerator how close the window of index from another window - titanium

everyone
I am using titanium with alloy, I have two windows which are index.js and main.js.
The window of index.js will be opened when the app run, there is a button in index, main will be opened if someone click the button. Main have another button which is used to close the index.
As you see, I am trying to close index window in main window.
Everything works fine in IOS, but when I test it in Android, I found a strange problem: when I click the button in main.js to close index window, all windows(both of index and main) are closed.
I tried many methods, like use Ti.APP.trigger/Ti.APP.addEventListener and send $.index or a callback function to main.js.
Could anyone help me, thanks.

in index.js use this
$.index.exitOnClose = false

Your solution is to set this property : exitOnClose = false as answered by #genocsb. It's available only on Android.
Actually, this property tells that which window should close the app upon closing the window itself. So, by default, the very first window has the its property exitOnClose = true.
In your case, do something like this:
- index.js
Alloy.Globals.Index = $.index;
Alloy.Globals.Index.open();
// If you will do this and press back button on index screen, then you will land to splash screen.
// Alloy.Globals.Index.exitOnClose = false;
- main.js
$.button.addEventListener('click', function (){
$.main.exitOnClose = true; // setting it to true will cause your app to close from main.xml screen on back button press
Alloy.Globals.Index.exitOnClose = false; // setting it to false here will ensure that you will not land to splash screen if back button is pressed.
Alloy.Globals.Index.close();
Alloy.Globals.Index = null;
});

Related

Is there anyway to prevent v-dialog from closing?

I'm utilizing <v-dialog> component to display a form for my web app. I want to implement an unsaved changes dialog to popup when the user aborts their changes without saving and either close/keep the dialog open depending on a button press. Unfortunately, I'm having a bunch of trouble figuring out exactly how to prevent the default closing actions done by the framework.
So from what I can tell, you can close a dialog 3 different ways:
Setting the v-model property to false.
Clicking outside of the v-dialog modal unless the persistent prop is set to true.
Pressing the escape key.
Let's not worry about the 2nd way to close the dialog I referenced above and assume it is set to true.
Approach #1:
My first approach was to only allow the user to exit the dialog if they hit a cancel button on the form. I quickly hit a snag when I tried to disable the use of the escape button.
Here's what I have tried so far: In my App.vue mounted function:
mounted () {
document.addEventListener('keydown', (e) => {
if (e.key === 'Escape') {
console.log('The escape key was pressed.')
e.preventDefault()
e.returnValue = false
e.stopImmediatePropagation()
}
})
}
This should work. The log message is displayed in the console, but the dialog still closes after the escape key is pressed. I know I should be using key codes here, but this is for readabilities sake. I've also tried keyup and keypress with no success. There has to be something wonky happening in either the Vue.js or Vuetify framework that's messing this up.
Approach #2:
After I failed miserably trying to disable the escape key, I had to try something different. I tried adding this code inside the watch function to try and keep the dialog open if they cancelled:
dialog (val) {
if (val) {
console.log('Dialog is true')
} else if (!val && !confirm('Unsaved changes, do you still want to exit?')) {
console.log('User Wants to Keep Dialog Open')
this.dialog = true
} else {
console.log('Dialog is False')
this.close()
}
}
When I try and close the dialog, the confirm message pops up, and I hit the cancel button. Then, for some reason, the confirm dialog opens again. So, I hit cancel again, then the dialog dismisses like nothing ever happened. Here's what the console reads:
User Wants to Keep Dialog Open
Dialog is true
User Wants to Keep Dialog Open
Dialog is true
I understand why the dialog watch method is being called again, what I don't understand is why the confirm dialog is showing again. That code should never be executing after cancelling the confirm message the first time. The log message shows that there's no way that code should be executing again. Something must be happening behind the scenes that I don't realize.
Anyone have experience with preventing the v-dialog component from closing? Or any help with my two approaches? Thanks in advance.
It's a property on the dialog:
<v-dialog persistent
That will force them to keep it open unless you call the closure programatically by toggling the model.

Cannot call method onCreateOptionsMenu () on startup for napp drawer

I have a problem only with nap drawer module.I have this code:
**drawer = NapDrawerModule.createDrawer({
//parameter for the drawer
});**
Then I have:
*
*drawer.getActivity().onCreateOptionsMenu = function(e) {
//code for creation menu**
}
Problem is that when I started application the method onCreateOptionsMenu() not called so my menu item not show up.When I pressed physical menu button it show up.
I noticed that this is problem only with NapDrawer.I tried make simple TI.UI.createWindow(),add method onCreateOptionsMenu() and it work.
I don't know what is a problem with drawer.I use titanium 5.0 and target android SDK 22.
I found the solution for the problem above.Anyone who has this kind of problem the next solution work for me.You need to add in your nap drawer create method next attribute:hamburgerIcon:true

Titanium Appcelerator Video Player Back Button on Android

I am new to Titanium App Development. I am making a title list of videos using a ListView. When I click on an item, the specific video plays fine. However when I press the back button in Android, the application exits instead of going back to the previous list of videos. I have tried android:back and androidback event of the window but still the same. How should I fix this??? By the way I am using the Alloy Framework in Titanium
index.js
videos.fetch({query: 'select * from '+ videos.config.adapter.collection_name + ' where video_id = '+ vid_id});
var args;
for (var vd=0 ; vd < videos.length; vd++){
var e = JSON.parse(JSON.stringify(videos.at(vd)));
args = {
parent_id : lsn_sub,
video_data : e.video_data
};
console.log(args.video_data);
var mediaview = Alloy.createController("media", args).getView();
mediaview.open();
media.js
var parent_view = args.parent_id;
var vid_media = args.video_data;
console.log("parent source: "+parent_view);
console.log($.vid_media.url);
$.vid_media.url = vid_media ;
$.media.addEventListener('androidback', function(e){
alert("android back");
});
views/media.xml
<Alloy>
<Window class="container">
<VideoPlayer id="vid_media" ns="Ti.Media" ></VideoPlayer>
</Window>
The back button exits the application, not going back to previous screen.
Set the model property of your second window true.
<SecondWindow class="container" modal="true"></SecondWindow>
Also set modal and exitOnClose true on your first window if you want to close the app when user press android back on your first screen.
<FirstWindow class="container" modal="true" exitOnClose></FirstWindow >
there is no to add android:back event for it.
Hope this will help you
Thank you for the great help #suraj and #victor, but I figured it out already.
The reason for it to be not working is because I was testing it only in the simulator, not on a real device. When I run it on the real device, the 'back button' of the android actually works fine. It stops my video and goes back to the previous screen.
We should really test on a real device rather than relying on a simulator. Have a great day! :)
Another possible solution
is to cancel the bubbling effect of the androidback event,
$.media.addEventListener('androidback', function(e) {
e.cancelBubble = true;
[...Your logic here...]
}

Durandal view no more displayed if user click quickly on menus

I use Durandal 2.0 & Breeze in my SPA.
I have a sidebar menu for my drivers (Chauffeurs) where user can click on submenus (Récents, Disponibles, Indisponibles) for calling my view with different parameters. This will fill a koGrid with data. The data is fetched in the activate call and the binding of the koGrid is done in the compositionComplete.
Everything goes well most of the time. Things goes wrong when I click very quickly on submenus (calling the same view). Example: I click on 'Récents' and immediately (without waiting for the view to display) I click on 'Disponibles'.
I have the following for the activate:
var activate = function (filterParam) {
filter(filterParam);
pagedDataSource.getDataFunction = getData;
pagedDataSource.getPredicatesFunction = getPredicates;
return pagedDataSource.reload();
};
And I have the following code for the compositionComplete:
var compositionComplete = function (view) {
bindEventToList(view, '.kgCellText', gotoDetails);
$('#mySearchGrid').attr('data-bind', 'koGrid: gridOptions');
ko.applyBindings(vm, document.getElementById('mySearchGrid'));
};
When I trace the activity, I noted that if user click quickly on submenus, the activate does not have the time to finish and is called again (for the second click of the user) and the compositionComplete does not execute. Then after that, nothing more happened visually. It seems blocked.
Any idea how can I prevent this problem?
Thanks.
The migration to the latest Durandal version 2.0.1 fixed the problem.

on(release) {...} or myButton.onRelease = function() {...} - action script 2 issues

I am having real confusion with some flash banners I'm creating and making the button into a clickable object which opens a web page.
I have been using this code for a while below, which works...
on(release){
getURL("http://www.the-dude.co.uk", "_blank");
}
And I placed this code on actual button within the actions panel
However I have been told the code above is very old and that I should use action script like below...
buttonInstance.onRelease = function() {
getURL("http://www.the-dude.co.uk", "_blank");
}
So I've tried to get this method below to work but nothing happens when I click the button, and I get one error, this...
So in a nutshell I cannot get this newer code to work! Ahh
Can anyone please help me understand where I am going wrong?
I have tried placing the new code in the Scene 1 of my actions. No worky..
And I've also tried placing the code below, actually on my button within the actions panel...
this.onRelease = function() {
getURL("http://www.the-dude.co.uk", "_blank");
}
Still not working.
My scene settings are alway this...
Any help would be great thanks.
You need to place the code below on the same timeline as the instance of the button (as you tried). And the instancename of the button must be "buttonInstance".
You can set the instance name in the properties panel when the button is selected.
buttonInstance.onRelease = function() {
getURL("http://www.the-dude.co.uk", "_blank");
}