You have to store some value in some variable of sharedpreference
. When user open your app,a check of the value of that variable every time will happen by retrieving it from sharedpreference
. Let the variable be boolean
, and the value retrieved is true
,then edit this value and change it to false
.While navigating through your app,nothing will hapeen to this variable's value.Even if the first activity
on which you displayed a webview is reopened in someway because the variable needs to be true to get your webview code executed (which you can accomplish by loading webview in an if statement checking your variable's value),but when oncreate
is called and it will check for that variable it will find t as false
. When ever user closes your application then again change that variable to true in the sharedpreferences
.And on next login to your app,the webview
will be loaded
SharedPreferences sp = getSharedPreferences("your_prefs", Activity.MODE_PRIVATE);
SharedPreferences.Editor editor = sp.edit();
editor.putBoolean("isItFirstTime", true);
editor.commit();
the you can get it as:
SharedPreferences sp = getSharedPreferences("your_prefs", Activity.MODE_PRIVATE);
Boolean myValue = sp.getBoolean("isFirstTime", false);
also see this How to use SharedPreferences in Android to store, fetch and edit values