I am not quite sure how to go about this as whatever I have tried till now, failed.
As you can see in attached image, most of the app consists of one webview and Javascript controlling the movement of user in app (in Webview).
The app starts in Activity A and then moves on to Activity B(as you can see in step 3) where device camera is opened and then user clicks the photo.
After the photo is clicked, I need to take user back to webview. I'd also need to know if user clicked any image or not (so, I'd need to pass something from Activity B to Activity A, which is not a huge deal once I figure out how to get to webview).
I have tried
setContentView(R.layout.activity_A);
which taked control back to Activity A which returns Activity with textview and webview but webview is empty then.
I have also tried webView.saveState
and webView.restoreState
but that also didn't work. However, as I am jumping through activities, I am not sure if I implemented it correctly.
So, I need someone to guide me how to get back to the webview (which needs to be in same state as the user left it before entering the Activity B). Have been stuck with this for far too long than I'd like to admit.
Graphical illustration of the problem is here. - Imgur Link (SO wouldn't let me post images here)
Code for WebView Activity :
public class SpeditionActivity extends Activity {
private static String show = null;
AtomicBoolean isScanning=new AtomicBoolean(false);
@SuppressLint("SetJavaScriptEnabled")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_audition);
TextView textView = (TextView) findViewById(R.id.textView);
textView.setText("Messages will appear here...");
String page = "<html>"
+ "<head>"
+ "<script type='text/javascript' src='file:///android_asset/jquery.js'></script>"
+ "<script type='text/javascript' src='file:///android_asset/audition.js'></script>"
+ "<link rel='stylesheet' type='text/css' href='file:///android_asset/style.css'>"
+ "</head>" + "<body style='margin: 0; padding: 0;'></body>"
+ "</html>";
final WebView webView = (WebView) findViewById(R.id.webView);
webView.setOnKeyListener(new View.OnKeyListener() {
@Override
public boolean onKey(View v, int keyCode, KeyEvent event) {
if(keyCode == KeyEvent.KEYCODE_BACK) {
Log.d("Back Button", "Back button clicked..");
webView.loadUrl("javascript:(function() { backKey(); })()");
return true;
}
return false;
}
});
WebSettings webSettings = webView.getSettings();
webSettings.setJavaScriptEnabled(true);
webSettings.setDomStorageEnabled(true);
webSettings.setUserAgentString("Audition 1.0");
webView.addJavascriptInterface(new AuditionJs(this), "Audition");
webView.loadDataWithBaseURL("http://www.url.com/audition", page,
"text/html", "UTF-8", null);
webView.setWebChromeClient(new WebChromeClient() {
@SuppressWarnings("deprecation")
public void onExceededDatabaseQuota(String url,
String databaseIdentifier, long currentQuota,
long estimatedSize, long totalUsedQuota,
WebStorage.QuotaUpdater quotaUpdater) {
quotaUpdater.updateQuota(estimatedSize * 2);
}
@Override
public void onCloseWindow(WebView window) {
AuditionActivity.this.finish();
}
}