Android - problems with a multi-level chain of actions

(Note that I searched the Internet for warnings, which I describe below, and wrote almost nothing about them.)

I work with a level 10 API. I have a preference screen (based on XML), and one of the options there creates a custom ListActivity as follows:

  • PreferenceActivity contains a parameter that creates ...
    • ListActivity that uses the dialog ...
      • setOnClickListener (), which contains the onClick () method, which (right before the finish () call) will launch the Activity () new Intent ...
        • sub-activity that triggers ...
          • AsyncTask , which performs a variable time job, which when making calls ...
          • onPostExecute (), which calls finish ()

The fact is that this works ... but I get a warning raft, 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:..... 

Curiously, this raft of warnings ONLY arises when a task is completed quickly! When I added the Thread.sleep () call to my AsyncTask to artificially inflate its runtime, it worked and did not give any warnings at all. In fact, as long as it takes more than (approximately) 500 ms to start, it works fine. (Note that I tried to use startActivityForResult () to achieve a greater effect - the same problem occurs.)


The goal is that the user selects a preference item, changes its setting, some processing takes place, and then the user returns to the settings menu in which they were launched.

I bet on the race state ... the order in which windows are destroyed depends on this runtime ... and I get the impression that when the sub-activity closes in front of the parent ListActivity, throw warnings. But spraying 1s sleep () in is not a smart solution unless it is some kind of Android bug (unlikely, but then again I already played a couple of them today).

So, what is the flaw in this mine leads to this stream of warnings? It would be nice to say "by preference, do it, then do it, and then finish," but I think what I'm doing is equivalent. Maybe not ... thoughts?


Edit: I decided to try to make this ListActivity as a custom dialog ... it was one of the most painful things I tried to do lately (getApplication () doesn't work, and many other things seem to go wrong ... it may to be inexperienced to some extent, but the dialogs are really not designed for this and ...

+6
source share
1 answer

Try the following two tasks:

  • Disable your dialog before calling the finish () function in your parent activity (PreferenceActivity).

  • Make sure you start your AsyncTask later in the sub-activity life cycle. I specifically think you should run it in onResume ().

My best guess is that AsyncTask calls the completion () function in the sub-activity before the sub-activity has the ability to fully run. Why does it matter? I'm not sure. Something to try. Good luck

+3
source

Source: https://habr.com/ru/post/899428/


All Articles