質問

I have a question about activity and dialog interaction. In my Android application I have a page that allow the user to scan a QRCode, and when a valid QRCode is scanned the application will open a Dialog. The problem is that I want to disable the automate scanning in the background activity when the Dialog is shown. Is there any way to disable the activity in background when the Dialog is in foreground? (even if the dialogue in question is on the same activity?).

I tried to call "onPause()" method but it doesn't works..

Thank you for your help!

If necessary I edit this post with part of the code :)

役に立ちましたか?

解決

Try this code:

public class MyClass extends Activity {

    private boolean mustScan = true;

    protected void onCreate(Bundle b) {
        if (mustScan) {
            // Just scan
            // Note: If you use a Thread with a while loop, use this:
            // while (true) {if (mustScan) {} }
        }
    }

    // This is the method you use to show the Dialog
    private void showResults (SomeResults here) {
        // Show the dialog
        // ...
        mustScan = false;
        // Also, in the OnClickListener of the buttons add "mustScan = true;"
    }
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top