How to stop calling the Activity again when device orientation is changed??

Posted by user1460323 on Stack Overflow See other posts from Stack Overflow or by user1460323
Published on 2012-06-16T08:09:34Z Indexed on 2012/06/16 9:16 UTC
Read the original article Hit count: 118

Filed under:
|

My app uses Barcode Scanner. I want to launch the scanner when I open the app so I have it in the onCreate method. The problem is that if I have it like that, when I turn the device it calls again onCreate and calls another scanner.

Also I have the first activity that calls the scanner. it has a menu so if he user presses back, it goes to that menu. If I turn the screen on that menu, it goes to barcode scanner again.

To solve it I have a flag that indicates if it is the first time I call the scanner, if it's not I don't call it again. Now the problem is that if I go out of the app and go in again it doesn't go to the scanner, it goes to the menu, becasuse is not the first time I call it.

Any ideas?? Is there a way to change the flag when I go out of my main activity or any other solution?? My code.

private static boolean first = true;
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    integrator = new IntentIntegrator(this);
    if (first) {
        first = false;
        integrator.initiateScan();
    }

}

© Stack Overflow or respective owner

Related posts about android

Related posts about android-intent