0

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();
        }
}
Patel
  • 1,478
  • 1
  • 13
  • 24

1 Answers1

0

It sounds like you are trying to capture a photo and display the results From the Documentation

You can send a request for an image to the Android System

Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
if (takePictureIntent.resolveActivity(getPackageManager()) != null) {
    startActivityForResult(takePictureIntent, REQUEST_IMAGE_CAPTURE);
}

Then you handle the results from the camera

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
  if (requestCode == REQUEST_IMAGE_CAPTURE && resultCode == RESULT_OK) {
    Bundle extras = data.getExtras();
    Bitmap imageBitmap = (Bitmap) extras.get("data");
    mImageView.setImageBitmap(imageBitmap);
  }
}

EDIT

The click result can be sent to ActivityA using FLAG_ACTIVITY_CELAR_TOP

Intent intent = new Intent(this, ActivityA.class)
            .setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)
            .putExtra(EXTRA_IMAGE_CLICKED, true);
startActivity(intent);

Will return to ActivityA as you left it and call onNetIntent allowing you to check the flag

@Override
protected void onNewIntent (Intent intent) {
  boolean imageWasClicked = intent.getBooleanExtra(EXTRA_IMAGE_CLICKED, false);
cyroxis
  • 3,661
  • 22
  • 37
  • I already am passed that stage. I am clicking the image in another activity. My question is how do I go back to previous activity with the image. The previous activity is mostly webview, and I need the user to see the screen where they were before they clicked the photo. I hope I am explaining it well. – Patel Apr 02 '15 at 17:54
  • Are you trying to pass the image back or just a flag indicating if the image was clicked? – cyroxis Apr 02 '15 at 17:57
  • No, I don't need to send images, just a flag will do. – Patel Apr 02 '15 at 18:00
  • @VivekPatel - I have updated my answer with instructions – cyroxis Apr 02 '15 at 18:10
  • Yes, it returns to the Activity A but the webview now is in the state as it was in Step 1 ( of the attached illustration in the question). – Patel Apr 03 '15 at 06:22