Issue
I am using WebView for loading a webpage in my app. I have enabled cache in-app so when the internet is not available the WebView loads caches.
Actually The problem here arrives is that when I open WebView for the first time when the app is installed or when caches are cleared when the caches are not yet saved in local and internet is off, It shows webpage is not available error.
So I decided to show AlertDialog warning showing that if no internet connection is available. But then it loads the no internet connection AlertDialog warning everytime when internet connection in not available.
I want that AlertDialog warning only when the cache is not available in storage , is there any option to check if cache is available in storage or not?
Solution
I got a solution to this problem by using SharedPreferences. I have done research on this and I found I can use SharedPreferences to check if the app is starting the first time or not. I added following in my code
SharedPreferences prefs = getSharedPreferences("prefs",MODE_PRIVATE);
boolean firstStart = prefs.getBoolean("firstStart",true);
And also I used if(firstStart) and called the
SharedPreferences.Editor editor = prefs.edit();
editor.putBoolean("firstStart", false);
editor.apply();
in the statement where I wanted to save the state.And all worked fine.
Answered By - Akshay Raut
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.