【问题标题】:Pause an Android activity when a Dialog is shown显示对话框时暂停 Android 活动
【发布时间】:2013-05-16 17:59:04
【问题描述】:

我有一个关于活动和对话交互的问题。在我的 Android 应用程序中,我有一个页面允许用户扫描二维码,当扫描有效的二维码时,应用程序将打开一个对话框。问题是我想在显示对话框时禁用后台活动中的自动扫描。 当对话框在前台时,有什么方法可以在后台禁用活动?(即使有问题的对话在同一个活动上?)。

我尝试调用“onPause()”方法,但它不起作用..

感谢您的帮助!

如有必要,我用部分代码编辑这篇文章:)

【问题讨论】:

  • 你不打电话给onPause(),平台会打电话。您需要停止扫描过程,而不是活动本身。

标签: java android android-activity dialog onpause


【解决方案1】:

试试这个代码:

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;"
    }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多