机器人 - 问题与多级活性链 [英] Android - problems with a multi-level activity chain

查看:162
本文介绍了机器人 - 问题与多级活性链的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

(请注意,我在网上搜索到了我所描述下方的警告,并纷纷拿出旁边见死不救。)

(Note that I've searched online for the warnings I'm describing below, and have come up with next to nothing about them.)

我正与API级别10.我有一个preference屏幕(基于XML的),和其中一个选项中有如下创建自定义ListActivity:

I'm working with API level 10. I have a preference screen (XML-based), and one of the options in there creates a custom ListActivity as follows:

  • preferenceActivity 包含一个用于创建一个选项...
    • ListActivity 这是采用对话...
      • setOnClickListener()的,其中包含一个onClick()方法(权利之前调用完成()的)将startActivity()的新意图...
        • 子活动它启动了一个...
          • 的AsyncTask 这确实可变的时间工作,这时候做电话...
          • onPostExecute()的这就要求面漆()
          • PreferenceActivity contains an option that creates a...
            • ListActivity which is a dialog that employs...
              • setOnClickListener() which contains an onClick() method that (right before calling finish()) will startActivity() a new Intent...
                • sub-Activity which starts up an...
                  • AsyncTask which does variable time work which when done calls...
                  • onPostExecute() which calls finish()

                  的一点是,它的工作原理......但我得到警告筏开始:

                  The thing is, it works... but I'm getting a raft of warning starting with:

                  10-16 21:59:25.010: WARN/WindowManager(170): Rebuild removed 4 windows but added 3
                  10-16 21:59:25.010: WARN/WindowManager(170): This window was lost:.....
                  

                  奇怪的是,这个木筏警告仅出现在任务执行快!当我添加了一个Thread.sleep()方法调用我的AsyncTask人为地夸大其运行时,它工作,任何扔没有任何警告。其实,只要时间超过(大约)500毫秒来运行它工作正常。 (请注意,我试图用startActivityForResult()没有更大的影响 - 出现了同样的问题)

                  Curiously, this raft of warnings ONLY comes up when the task executes quickly! When I added a Thread.sleep() call to my AsyncTask to artificially inflate its runtime it worked and threw no warnings whatsoever. In fact, as long as it takes more than (roughly) 500 ms to run it works fine. (Note that I tried using startActivityForResult() to no greater effect - the same problem occurs.)

                  的目标是,在用户选择一个preference条,它们改变其设置时,一些处理发生,然后用户被留在后面,他们开始对preference菜单

                  The goal is that the user selects a preference item, they change its setting, some processing takes place, and then the user is left back at the preference menu they started on.

                  我敢打赌,这是一个竞争条件......的顺序窗户被破坏取决于运行时...和我得到​​的IM pression,以前当次活动关闭了家长ListActivity警告抛出。但是,洒1秒的睡眠()的不是一个合理的解决方案,除非这是某种形式的Andr​​oid的bug(不可能的,但话又说回来,我转载了几个与今天的话)。

                  I'm betting it's a race condition... the order in which the windows are destroyed varies depending on that run-time... and I get the impression that when the sub-Activity closes before its parent ListActivity the warnings get thrown. But sprinkling a 1s sleep() in isn't a reasonable solution unless this is some sort of Android bug (unlikely, but then again I've reproduced a couple of those today already).

                  那么,什么是在这个缺陷我,导致警告此流?这会是不错的说,在preference,这样做,那么做,然后完成但我觉得我在做什么是等价的。也许不是...想法?

                  So, what's the flaw in this my that leads to this stream of warnings? It'd be nice to say "on preference, do this, then do that, then finish" but I think what I'm doing is the equivalent. Maybe not... thoughts?

                  编辑:我决定尝试做这个ListActivity作为一个自定义对话框......那是我一直试图做的,最近更痛苦的事情之一(getApplication()无法正常工作和许多其他事情似乎走错了......这可能是经验不足,在一定程度上,但对话真的不意味着这要么...

                  I decided to try doing this ListActivity as a custom Dialog... that was one of the more painful things I've tried to do lately (getApplication() doesn't work and lots of other things seem to go wrong... it may be inexperience to some extent, but dialogs really weren't meant for this either...

                  推荐答案

                  请尝试以下两件事情:

                  • 在其父活动(preferenceActivity)调用完成()前解散你的对话框。

                  • Dismiss your dialog before calling finish() on its parent activity (PreferenceActivity).

                  请确保您的子活动的整个生命周期后开始您的AsyncTask。我特别想你应该启动它的onR​​esume()。

                  Make sure you are starting your AsyncTask later in the sub-activity's lifecycle. I'm specifically thinking you should launch it in onResume().

                  我最好的猜测是,AsyncTask的是调用完成()的子活动,子活动有机会完全启动之前。为什么这样做很重要?我不确定。一些尝试,但。祝你好运!

                  My best guess is that the AsyncTask is calling finish() on the sub-activity, before the sub-activity has had a chance to fully start up. Why that would matter? I'm not sure. Something to try though. Good luck!

                  这篇关于机器人 - 问题与多级活性链的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆