问题
- Activity A = webView which contains smartchatbot(used for answering simple questions) url.
My question is very simple. All i want to achieve is when i go into Activity A and use the smartchatbot. Once i ask few questions to the smartchatbot, and the smartchatbot gives me a link to go to other page/activity. Once i view the page and return back to Activity A which contains the smartchatbot, i want all the previous questions i asked to the smartchatbot to be there. Not only that, even if i click back button the previously questions have to be there. I have tried the movetasktoback() method but when i click back in Activity A, the back button acts like a home button and goes to the main home screen of the phone.
How is it possible to achieve this?
I have tried to save the webView state in Acivity A by overriding the onSaveInstanceState method. However, this onSaveInstanceState method was never called. Im not sure whether this method is the suitable solution for what i want to achieve. Please help me. Thanks in advance
private WebView webView;
@Override
protected void onSaveInstanceState(Bundle outState){
super.onSaveInstanceState(outState);
webView.saveState(outState);
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
if(savedInstanceState != null){
webView.restoreState(savedInstanceState);
}else{
setupWebViewUI();
}
}
private void setupWebViewUI() {
webView.loadUrl("contains the smartchatbotURL");
WebSettings webSettings = webView.getSettings();
webSettings.setJavaScriptEnabled(true);
}
}
来源:https://stackoverflow.com/questions/59353675/is-it-possible-to-prevent-a-webview-from-refreshing-reloading-when-we-go-to-anot