9

So, after I finish my scanner activity with

      btn_take_photo.setOnClickListener(new FloatingActionButton.OnClickListener() {
        @Override
        public void onClick(View view) {
            String carde = cardnumberbox.getText().toString().trim();
            if (carde.matches("")) {
                Toast.makeText(getApplicationContext(), getString(R.string.Skan_Udfyld_Kort_Nummer), Toast.LENGTH_SHORT).show();
                cardnumberbox.requestFocus();
                return;
            }
            Intent i = new Intent(ScanActivity.this, CameraActivity.class);
            i.putExtra("EXTRA_SESSION_ID", carde);
            startActivity(i);

        }
    });

to go to my cam activity so I can take some pictures and go back with

    public void btn_aprove2(View view) {
    Intent i = new Intent(CameraActivity.this, ScanActivity.class);
    String counts = count.getText().toString().trim();
    i.putExtra("EXTRA_SESSION_IDs", counts);
    String carde = cardnumberbox2.getText().toString().trim();
    i.putExtra("EXTRA_SESSION_ID", carde);
    startActivity(i);
    finish();

to the scanneractivity again. My scanner does not work properly but if I then press the back button it does go back to the scanneractivity again instead of my menu so it seems like the scanneractivity is running twice and only 1 of them are functional but is here where it confuses me

cause if do not press the btn_aprove2 button and just use the back button instead i gets the exact same issue but here my scanneractivity is not runned twice as when i press the back button it just takes me back to the menu

a video of the issue

by removing my screen orientation from the manifest (so i can rotate it) my scanner do now work but only if i first rotate to landscape and rotate it back to potrait

and i see in the log is that it is only calling the oncreate when rotating and only on resume and pause on the button's(startactivity/finnish)

I am totally lost on how to get this to work.

on github with api demo and documentation in the wiki and with thoose classes that are being used

17
  • Are you using any library for scanning through your camera.?
    – droidd
    Mar 24, 2017 at 12:22
  • i do not scan througth the cam as this is a newland n5000 so there is a inbuild 2d barcode reader for that i am using their api zltd_decoder which you can get by request but i have it uploaded here drive.google.com/open?id=0ByzowKEghTyWcFVXSlpJTzlpRjA Mar 24, 2017 at 13:06
  • i wonder if there might be a way to make it act the same way when i opening it up from the menu? as i thougth i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); and finish(); should do Mar 24, 2017 at 13:12
  • I have two questions: 1. as long as you are going to CamerActivity to fetch a result, why don't you launch it with startActivityForResult(). 2. Why are you applying FLAG_ACTIVITY_NEW_TASK?
    – azizbekian
    Mar 24, 2017 at 13:34
  • 1
    i mean, the absence of exception handling might be hiding the cause of a possible problem and we're here wasting our time when a stack trace could point to the answer you need
    – nandsito
    Mar 29, 2017 at 14:50

1 Answer 1

4
+25

If you just jump to the Camera activity to get some data, I'd recommend you to start the activity for a result (startActivityForResult) without finishing the Scanner activity at all. This would give you a proper working back stack (using back button to go back from Camera to Scanner).

Besides that why are you using i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);? You are starting a new activity and finishing the old one. I don't see why this flag is really needed. What is your android:launchMode in your manifest and are you sure you know what FLAG_ACTIVITY_NEW_TASK is doing and it is what you want?

Anyways from what you told us it looks like your example really should utilize startActivityForResult() without calling finish():

  1. Press menu button on some activity
  2. Start camera and do something
  3. Press some button to start Scanner
  4. Scan something and finish the scanner with the result (or cancel the scanner by clicking back)
  5. Retrieve the result of the scanner in the camera and do something with it or continue with the previous workflow when scanner was cancelled
  6. Once you are finished with your workflow, finish the camera so you end up in your activity where you started the camera
17
  • i haven't setted any launchmode up in my manifest using startActivityForResult(i, 1) without flag's and finish didn't solved the issue Mar 29, 2017 at 15:35
  • I think I don't quiet understand your flow. So from the menu, you open the camera. From the camera you go to the scanner. From the scanner you go back to the camera and from the camera again to the scanner?
    – xxtesaxx
    Mar 29, 2017 at 15:45
  • actualy is the other way around menu>scanner>camera>scanner>finish Mar 29, 2017 at 16:11
  • So you would have to start the camera activity for result without finishing the scanner. e.g. Intent intent = new Intent(this, Camera.class); intent.putExtra("EXTRA_SESSION_ID", carde); startActivityForResult(intent, REQUEST_CODE_TAKE_PICTURES); Don't call finish on the scanner and don't set the flag. Instead implement onActivityResult in your scanner activity
    – xxtesaxx
    Mar 29, 2017 at 16:15
  • what is REQUEST_CODE_TAKE_PICTURES as it cannot resolve symbol Mar 29, 2017 at 16:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.