I'm having an issue with my code and I'm not sure if the way I'm writing my program is the best way to write it.
To cut to the chase..
in the onCreate
method of my application, setContentView(R.layout.activity_main);
is called.
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//extra code..
//there is a lot of code from here on out, but it is not relevant to my question.
}
A WebView is displayed with 4 images loaded onto the webview. The user can click either one of the images and it will take the user to 1 of 4 different websites, with each image corresponding to a different url.
In this application, I am overriding public void onBackPressed()
Now here is the problem.
When the user broweses the webpage and has a "history"(all of this is handled in the webview), meaning the user can click back, it will keep going back to the beginning of the page, right to where the user started when they clicked one of the images.. But it does NOT go back to the view from where the program originally starts.. meaning that when the user is browsing a page in my webview and they click the back button , the furthest it goes back to is the start of the webpage.
What I want it to go back to is to the beginning of the app, where the 4 images appear on screen and the user can click a different image, (i.e. a different webpage to select).
What I've tried
To solve this probelm, I assumed I would try and create a condition. If the webpage cannot go back any further, a method would call setContentView(R.layout.activity_main)
again.
This DOES work.. with only one big problem. When the layout loads, all of the 4 images do not respond to any sort of clicks, and the application will not exit even with the press of the back button.
No exceptions are thrown, no crashes occur.
What would be a good solution to my problem?
And if needed, I can post code.