Question

I am developing an html app for android. I have some html files in my asset folder. The index.html file loads when app is started. In index.html I have a link to categories.html. When I choose any category and after pressing back button(hardware, there is no button in html) it goes to categories.html. But the problem is that I have option switch between categories from the categories, so when I press the back button it goes to the previous category.

For eg: I have 3 categories - green, yellow and red. I selected the category green. From green, switched to red, and from red to yellow. When I press the back button from yellow it goes to red. But it should go to categories.html

Is there any solution ?

Was it helpful?

Solution

  1. Search Google - So many answers
  2. Search Stackoverflow - No need if you did step 1

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if(event.getAction() == KeyEvent.ACTION_DOWN){
            switch(keyCode)
            {
            case KeyEvent.KEYCODE_BACK:
                //open category page here
                return true;
            }
    
        }
        return super.onKeyDown(keyCode, event);
    }
    

See How to go back to previous page if back button is pressed in WebView?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top