back button is working on emulator but it is not working in device in android

I'm new to android development. I have index page and I'm displaying every links in the same page using div concept.

Now I want to use the back button for my application. I have developed code to handle the div and it is working in the AVD(Andriod Virtual Device 5556) but if I upload the *.apk into my device it is not working.

I'm waiting for your reply. Please help me.

This is my sample code:

HTML Sample code:

<div id="photo_playlist">       
    <div id="photo_playlist_home">
        <div class="HomePhotoDetailsBar">
            <div class="innerplay" id="innerrow10833">
                <a style="text-decoration:none;" onClick="player('1');">
                    <div class="thm_image">
                        asdasdasdadadad
                    </div>
                    <div class="video_details_n">
                        <div class="video_details_premium">Premium</div>
                        <div class="photo_details_head">Zoe Duchesne</div>
                        <div class="video_details_premium">5 photos</div>
                    </div>
                    <div class="video_arrow">dsfsfsfss</div>
                </a>
            </div>
        </div>
    </div>
</div>
<div id="detail">
    <div id="playlist"></div>
</div>
<div id="player">
    <div id="photocontainer"></div>
</div>

JS Sample:

function photos() {
    resetPhotoPlaylist();
    $('#photo_playlist').addClass('current');
    $('#photo_playlist').css('display','block');
    $('#photo_playlist_home').addClass('current');
    $('#photo_playlist_home').css('display','block');
    $('#player').css('display','none'); 
    $('#playlist').css('display','none');
    $('#detail').css('display','none');
    $('#photocontainer').css('display','none');
}

function resetPhotoPlaylist() {
    $('#second_playlist').removeClass('current');
    $('#second_playlist').css('display','none');

    $('#playlist').removeClass('current');
    $('#playlist').css('display','none');

    $('#photocontainer').removeClass('current');
    $('#photocontainer').css('display','none');

    $('#photo_playlist_home').removeClass('current');
    $('#photo_playlist_home').css('display','none');
}

function back() {

    history_.pop();
    var previous = history_.pop();
    if(history_.length==0) {
        history_ = ["home"];
    }

    switch(previous) {
        case "home"     :home();break;
        case "news"     :news();break;
        case "video"        :video();break;
        case "player"       :player(1);break;
        case "gallery"      :gallery(1);break;
        case "photos"       :photos();break;
        case "reader"       :reader(1);break;
        case "searchresult" :searchresult();break;
        case "search"       :search();break;
    }
}

function addToHistory(page) {

        history_.push(page);
}

Java Code:

public void onBackPressed()
    {
        appView.loadUrl("javascript:back();");
    }

Thanks, Rajeevgandhi. S

Answers


Try

appView.loadUrl("javascript:(function() { back();})()");

Need Your Help

How does Java resolve a relative path in new File()?

java file relative-path

I am trying to understand the way Java resolves relative path in while creating a File object.

Drupal Block View Execute Javascript function

javascript php function drupal drupal-blocks

This would be my first custom module I am creating, and having a few grey hair's for something as simple as rendering a js function into a drupal block module.