当屏幕被锁定时,即使设置了标志FLAG_SHOW_WHEN_LOCKED,对话框也会消失

时间:2016-01-04 15:27:51

标签: android android-activity dialog keyguard

我在应用程序上工作,我面临一个奇怪的问题。当屏幕被锁定时,我会在应用程序被激活时出现一个对话框,它可以正常运行Lolipop,KitKat和旧版本。问题似乎只出现在V6 Marshmallow中:对话框出现一秒钟,然后它似乎在后台消失。但是,如果按下对话框应该在的位置,对话框的活动就像对话框一样!我找到了很多关于这个问题的答案,但似乎没有一个对我有用。 在onCreate()中,我设置了nessecary标志:

<?php
echo 'hello, ' . $_SESSION['username'];
echo '            ';
echo $_SESSION['id'];
?>

<div>   
   <table class="table table-bordered table-hover">
        <thead>
            <tr>
                <th class="TableCol1"> Username </th>
                <th class="TableCol2"> First Name </th>
                <th class="TableCol3"> Last Name </th>
                <th class="TableColOpt"> Options </th>
            </tr>
        </thead>
        <!-- This is the category fields on the list. -->
        <tbody>
            <?php
            //$check = $sqlQuery->fetch(PDO::FETCH_ASSOC);
            while ($check)  {

                echo '<tr>';
                echo '<td class="prEach1">' . $check['Username'] . '</td> ';
                echo '<td class="prEach1">' . $check['FirstName'] . '</td> ';
                echo '<td class="prEach3">' . $check['LastName'] . '</td> ';
                echo '<td class="prEach4 optlinks"> '
                . '<a href="profile.php?UserID='.$check['UserID'].'">View</a> '
                . '</td>';
                echo '</tr>';

                $check = $sqlQuery->fetch(PDO::FETCH_ASSOC); //THIS SHOULD BE AT THE BOTTOM JUST BEFORE THE WHILE LOOP ENDS
            }
            ?>
        </tbody>
        <!-- This is the get methods of the properties, where the output of the user put in the Property form will be shown -->
    </table> 
</div>

我也试过禁用没有结果的键盘锁:

// allow to be shown when screen is locked
        Window win = getWindow();
        WindowManager.LayoutParams winParams = win.getAttributes();
        // winParams.flags |= WindowManager.LayoutParams.FLAG_FULLSCREEN;
        // winParams.flags |= WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN;
        winParams.flags |= WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED;
        // winParams.flags |= WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON;
        win.setAttributes(winParams);

这是我在AndroidManifest.xml中的声明:

KeyguardManager myKeyGuard = (KeyguardManager) Context.getSystemService(Context.KEYGUARD_SERVICE);
        KeyguardManager.KeyguardLock myLock = myKeyGuard.newKeyguardLock(KEYGUARD_SERVICE);
        myLock.disableKeyguard();

我注意到如果从主题中删除Dialog样式,它就可以了。但我需要它成为一个对话!

请记住,此代码适用于除V6之外的所有版本!有什么想法吗?

0 个答案:

没有答案