Saturday 15 May 2010

android - Using FLAG_ACTIVITY_REORDER_TO_FRONT to switch among persistently running UI activities leads to "no window focus" error -


My aim is to keep two UI activities alive and switch between them in front and back, without killing anyone / again Getting Started From Them . When I am running in the background in a previous activity (the current) resume window lose focus

I: But there FLAG_ACTIVITY_REORDER_TO_FRONT a use for it The serious side effects have proved this problem by spending 5 minutes to create a simple application with "Hello World" activities.

  1. App Activity starts with A, which is just a button (nothing else) to "launch b".
  2. button - the implementation of startActivity (FLAG_ACTIVITY_REORDER_TO_FRONT, ActivityB.class)
  3. Activity B is activated, the call shows only a button Runs. "A Launch"
  4. This Button - .. The implementation of startActivity (FLAG_ACTIVITY_REORDER_TO_FRONT, ActivityA.class)
  5. activity is an added onResume () required and everything looks fine (I can again see the activity A content).
  6. Press the device's previous key and this set of errors will be 100% of the time:

/ WindowState (513) I: Win death: window {5294687c u0 com.android.launcher / com.android.launcher2.Launcher}

(8066) W / ViewRootImpl:> event : KeyEvent {action = ACTION_DOWN, keycode = KEYCODE_BACK, scanCode = 0, metaState = 0, flag = 0xc8, repeatCount = 1, EVENTTIME = 14,965,546, downtime = 14,965,045, DeviceID = -1, Source = 0x101}

(The practical result of window death is "crash" from the user's perspective - Android throws users out of the app on the home screen, though technically application background

I debug it and found that activity is visible. But not the focus because the activity A onWindowFocus is not changed () is not called as it normally does (still called resume). This activity is anything with fact with B, is still active in the background (even though B has lost the focus clearly - onWindowFocusChanged (wrong) was called for B, As well as ontop ()). I know this because if I call on Activity B immediately after step 4, Activity A's On-Wind Focus (true) will be called and all this is normal. The fact is that Activity B is still active, but should not in any way focus on restarting activity like it should do, whether it is an Android bug or am I missing something ?

Note that if there are multiple views in Activity A and I want to touch one of those sequences after step 6 above, then error me, "due to any window focus due to droping event" For no reason 100% of the time is

To work for the solution given in the activity Focus is not happening. / P>

  protected void onNewIntent {intent} {super.onNewIntent}; If ((intent.getFlags () | Intent.FLAG_ACTIVITY_REORDER_TO_FRONT) & gt; 0) {if (android.os.Build.VERSION.SDK_INT & gt; = 19 & amp; & amp; isTaskRoot ()!) {ActivityManager tasksManager = (ActivityManager) getSystemService (ACTIVITY_SERVICE); TasksManager.moveTaskToFront (getTaskId (), ActivityManager.MOVE_TASK_NO_USER_ACTION); }}}  

For this AndroidManifest.xml

  and use of Lieutenant-permission Android: name = "Android.permission .REORDER_TASKS "/>  

I really get such error in this problem in espresso :

java.lang.RuntimeException: Wait for Do not request layout for more than 10 seconds to focus on the root hierarchy window. If you've specified a non default root mounter, then it can choose a root that never takes focus. Otherwise, something is seriously wrong.


No comments:

Post a Comment