Android:当对话框在后台关闭时,活动不会获得焦点

发布于 2024-12-15 20:24:44 字数 1640 浏览 1 评论 0原文

当我按主页按钮将应用程序推送到后台并随后恢复它时,有时应用程序 UI 元素没有焦点。整个屏幕呈灰色(亮度降低),并且无法单击屏幕上的任何按钮。此外,如果除了音量、电源和主页之外的硬件按钮不起作用。唯一的解决方案是强制停止应用程序并重新启动。 此问题不可重现,并且很少在随机情况下发生。还有其他人在他们的应用程序中看到过这个问题吗?

编辑::::::::::

我发现了真正的问题。这更具重现性:我点击了一个 Web 服务来下载 AsyncTAsk 中的数据,并显示 ProgressDialog。当对话框显示时,如果用户按下主页按钮,应用程序将被发送到后台。同时,下载完成,对话框消失。现在,当用户返回应用程序时,activity 不会重新接收焦点,本质上,它不会再接收任何触摸事件

此处添加了异步任务的代码:

class GetStoresTask extends AsyncTask<String, Void, List<String>> {
    ProgressDialog pd;

    protected void onPreExecute() {
        super.onPreExecute();
        pd = ProgressDialog.show(DisplayStoresActivity.this,
                getResources().getString(R.string.pleaseWait),
                getResources().getString(R.string.dialogFindingStores),
                true, true);
        pd.setOnCancelListener(new OnCancelListener() {

            public void onCancel(DialogInterface dialog) {
                // TODO Auto-generated method stub
                GetStoresTask.this.cancel(true);
            }
        });
    }

    protected List<Message> doInBackground(String... params) {
        // carried out my download here
                          return downloadStoresList();
    }

    protected void onPostExecute(List<String> result) {
        // TODO Auto-generated method stub
        pd.dismiss();
                          adapter.notifyDataSetChanged();
        super.onPostExecute(storesList);
    }

似乎当应用程序处于后台并且对话框被关闭时,焦点不会转移到我的 Activity 的对话框。有没有人遇到过类似的问题,或者有什么解决方案吗?

When i press the home button to push my application to the background, and resume it afterwards, sometimes the app UI elements do not have focus. The entire screen is sort of greyed out (brightness is decreased) and none of the on screen buttons, can be clicked. What's more, event the hardware buttons except volume, power and home do not function. The only solution is to force stop the app and start again. This issue is not reproducible, and happens only rarely on random occasions. Has anyone else seen this issue in their applications ?

EDIT ::::::::::

I found the real issue. This is more reproducible: I hit a web service to download data in an AsyncTAsk, and show a ProgressDialog. While the dialog is showing, if the user presses home button., the app is sent to background. Meanwhile, the download is complete, and the dialog is dismissed. Now when the user goes back to the application, the activity does not receive focus back, in essence, it does not receive any more touch events.

Added code of the async task here:

class GetStoresTask extends AsyncTask<String, Void, List<String>> {
    ProgressDialog pd;

    protected void onPreExecute() {
        super.onPreExecute();
        pd = ProgressDialog.show(DisplayStoresActivity.this,
                getResources().getString(R.string.pleaseWait),
                getResources().getString(R.string.dialogFindingStores),
                true, true);
        pd.setOnCancelListener(new OnCancelListener() {

            public void onCancel(DialogInterface dialog) {
                // TODO Auto-generated method stub
                GetStoresTask.this.cancel(true);
            }
        });
    }

    protected List<Message> doInBackground(String... params) {
        // carried out my download here
                          return downloadStoresList();
    }

    protected void onPostExecute(List<String> result) {
        // TODO Auto-generated method stub
        pd.dismiss();
                          adapter.notifyDataSetChanged();
        super.onPostExecute(storesList);
    }

It seems when the app is in background, and the dialog is dismissed, the focus is not transferred to the dialog to my Activity. Has anyone faced similar problems, or have any solution to this ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

朱染 2024-12-22 20:24:44

这不是一个常见的问题。当您在恢复屏幕/应用程序时执行一些繁重/复杂的操作导致用户界面卡住时,就会发生这种情况。因此分析各种实现。

not a usual issue . it happens when you do some heavy/complex operations on resuming screen/app which stuck the UI. so analyze various implementations .

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文