Android - Application restarting after minimization

Asked

Viewed 984 times

0

I have an android application, where I only have a screen that is a Webview. However, when the user accesses a page of the site, for example: meusite.com.br/contact and minimizes the app. When he reopens the app, instead of going back to the page he was on, he goes back to the home page (in meusite.com.br). I’ve already added events to update the variable that modifies the url, to modify it when the url is modified. I also added events to save the application status and still continues the same error.

  • Hello User and welcome to [en.so]. Provide more details on your problem, including some of the current sources and examples of what you’ve tried. Take the [tour] and visit [help] mainly on the topic [Ask]

  • 1

    Enter all the code referring to Webview...

  • Post the code.

1 answer

2

To prevent the application from "rebooting" after minimizing, you must save the instance

For this you must use the methods onSaveInstanceState, onRestoreInstanceState and super.onCreate in his Activity.

It would look something like (read the comments in the code):

public class MainActivity extends Activity {
    private WebView meuWebView;//Seu webView

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);//"super" envia o comando para classe "parent"
        ...
    }

    @Override
    protected void onSaveInstanceState(Bundle outState){
        super.onSaveInstanceState(outState);//Salva Activity 
        meuWebView.saveState(outState);//Salva WebView
    }

    @Override
    protected void onRestoreInstanceState(Bundle savedInstanceState){
        super.onSaveInstanceState(savedInstanceState);//Restaura o Activity 
        meuWebView.restoreState(savedInstanceState);//Restaura o WebView
    }
}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.