Android - Application restarting after minimization [closed]

0

I have an android application, where I only have one screen that gets a WebView. However, when the user accesses a page of the site, for example: mysite.com.br/contact and minimizes the app. When he reopens the app, instead of returning it on the page it's on, it goes back to the home page (at miite.com). I have already added events to update the variable that modifies the url, to modify it when the url is modified. I have also added events to save the state of the application and still the same error continues.

    
asked by anonymous 02.01.2015 / 16:50

1 answer

2

To prevent the app from "restarting" after minimizing, you should save the instance

For this you should use the methods onSaveInstanceState , onRestoreInstanceState and super.onCreate in your 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
    }
}
    
02.01.2015 / 21:23