1
votes

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.

3

3 Answers

1
votes

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

1
votes

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! :)

0
votes

Another possible solution is to cancel the bubbling effect of the androidback event,

$.media.addEventListener('androidback', function(e) {
    e.cancelBubble = true;
    [...Your logic here...]
}