简体   繁体   English

Android:在后台关闭对话框时,Activity无法获得焦点

[英]Android: Activity does not receive focus when dialog is dismissed in background

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. 当我按下主页按钮将我的应用程序推到后台,然后再恢复运行时,有时应用程序UI元素没有焦点。 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 . 这更具可复制性:我点击了一个Web服务以在AsyncTAsk,下载数据AsyncTAsk,并显示一个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 . 现在,当用户返回到应用程序时,该activity不会再收到焦点,实质上,它不会再收到任何触摸事件

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 . 看来当应用程序在后台运行并且关闭对话框时,焦点没有转移到对话框的“我的Activity Has anyone faced similar problems, or have any solution to this ? 有没有人遇到类似的问题,或者对此有任何解决方案?

not a usual issue . 这不是通常的问题。 it happens when you do some heavy/complex operations on resuming screen/app which stuck the UI. 当您在恢复屏幕/应用的界面上执行一些繁琐/复杂的操作而卡住UI时,就会发生这种情况。 so analyze various implementations . 因此分析各种实现。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM