As you yourself indicated, since the saved state is null, you cannot expect onCreate to return your webview to the last page opened. You need to do two things:
Make sure your login page, which is your first page, is redirected to the relevant content page when it detects that the user has already registered. Since you already use cookies, this is trivial.
Then move the onPause method to save the current web browser URL.
@Override protected void onPause() { super.onPause(); SharedPreferences prefs = context.getApplicationContext(). getSharedPreferences(context.getPackageName(), Activity.MODE_PRIVATE); Editor edit = prefs.edit(); edit.put("lastUrl",webView.getUrl()); edit.commit();
You can then read this property in the onCreate method and load the URL as needed. If preference is defined, download it if you donβt download the login page (which should be redirected to the first page of content if it is already logged in)
UPDATE is what your onResume might look like. Also added one line to the above onPause () method.
@Override protected void onResume() { super.onResume(); if(webView != null) { SharedPreferences prefs = context.getApplicationContext(). getSharedPreferences(context.getPackageName(), Activity.MODE_PRIVATE); String s = prefs.getString("lastUrl",""); if(!s.equals("")) { webView.loadUrl(s); } } }
e4c5 Sep 29 '15 at 3:11 2015-09-29 03:11
source share