ANR在com.android.launcher攻回来后,回来后、com、ANR、launcher

2023-09-08 08:30:53 作者:忘记过往

当我安装我在某些设备上的应用程序(好像是4.4.4或更高版本)我有时会看到下面的ANR在com.android.launcher以下步骤后:

从活动一,推出b活动 在活动B,preSS系统返回键和onBack pressed()的b活动重新开张活动的方法(code是如下图)。 在系统返回键保持在pressed状态5秒,屏幕变黑,我的应用程序被关闭,发射出现。调查日志显示在启动过程中的ANR。   

ANR在com.android.launcher   (com.android.launcher / com.android.launcher2.Launcher)原因:输入   调度超时(等待,因为没有窗口具有焦点,但有   是一个集中的应用程序,它最终可能会增加一个窗口时,   完成启动。)

请注意,ANR发生在com.android.launcher(而不是在我的应用程序)。

顺便说一句,我没有做我的onBack pressed /的onPause /的onStop方法的一个昂贵的操作。

日志也显示,onBack pressed()时,ANR时不被调用 - 很奇怪的行为,因为你可以在这里看到:

  ##的用户从Android的启动开始活动一
D /活动答:onResume()
D /活动答:的onClick():开始b活动
D /活动答:在onPause()
D / b活动:onResume()

##用户点击系统恢复键(和onBack pressed()启动活动A)
D / b活动:onBack pressed():启动活动一
D / b活动:在onPause()
D /活动答:onResume()
D /活动答:的onClick():开始b活动
D /活动答:在onPause()
D / b活动:onResume()

##用户点击系统恢复键(但onBack pressed()不会被调用,而是一个ANR发生)
I / InputDispatcher(557):ANR在com.android.launcher
D / b活动:在onPause()
 

下面是我的onBack pressed()方法:

 公共无效onBack pressed(){
    意图int​​entStartRoot =新意图()setComponent(新组件名(本,ActivityHome.class))。
    intentStartRoot.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
    startActivity(intentStartRoot);
}
 
android launcher2 –

解决方案

这可能是在Android框架的错误。我今天测试了约12个设备,并注意到可靠地发生在运行这些版本的Andr​​oid的Nexus型设备,这个错误:

4.4.4 5.0.1 5.0.2

有趣的是,运行Android的版本相同的三星设备不出现此问题。安卓5.1及更高版本似乎是在说我看到com.android.launcher没有更多ANRS更好;但是我现在看到ANRS在com.google.android.googlequicksearchbox。

我注意到,我的活动是压倒一切的onBack pressed()后的工作解决此问题,而无需调用super.onBack pressed()。 当我加入super.onBack pressed(),该ANRS就走了。但是,这是不是一个完整的解决方法,因为调用super.onBack pressed()完成了我的活动,对此我不想要的。

我希望这可以帮助别人。

请参阅:使用FLAG_ACTIVITY_REORDER_TO_FRONT到中持续运行的UI活动切换导致[否窗口焦点"错误

请参阅:使用FLAG_ACTIVITY_REORDER_TO_FRONT推出previous活性放大器时,onBack pressed;:的Andr​​oid-L的问题冻结了一段时间应用

另外,我发现,似乎与谷歌的网站上的错误条目: 的https://$c$c.google.com/p /安卓/问题/详细信息?ID = 91534

When I install my app on certain devices (seems to be 4.4.4 and later) I sometimes see the following ANR in com.android.launcher after the following steps:

From Activity A, launch Activity B In Activity B, press system back key and in the onBackPressed() method of Activity B relaunch Activity A (code is below). System back key remains in pressed state for 5 seconds, the screen turns black, my app gets closed and Launcher comes up. Investigating the logs shows an ANR in the Launcher process.

ANR in com.android.launcher (com.android.launcher/com.android.launcher2.Launcher) Reason: Input dispatching timed out (Waiting because no window has focus but there is a focused application that may eventually add a window when it finishes starting up.)

Notice that the ANR is occurring in com.android.launcher (not in my app).

Btw, I am NOT doing an expensive operation in my onBackPressed/onPause/onStop methods.

The logs also show that onBackPressed() is not being invoked when the ANR occurs - very odd behavior as you can see here:

## User starts Activity A from Android Launcher
D/Activity A: onResume()
D/Activity A: onClick(): start Activity B
D/Activity A: onPause()
D/Activity B: onResume()

## User taps system back key (and onBackPressed() launches Activity A)
D/Activity B: onBackPressed(): start Activity A
D/Activity B: onPause()
D/Activity A: onResume()
D/Activity A: onClick(): start Activity B
D/Activity A: onPause()
D/Activity B: onResume()

## User taps system back key (but onBackPressed() is not invoked. Instead an ANR occurs)
I/InputDispatcher(  557): ANR in com.android.launcher
D/Activity B: onPause()

Here is my onBackPressed() method:

public void onBackPressed() {
    Intent intentStartRoot = new Intent().setComponent(new ComponentName(this, ActivityHome.class));
    intentStartRoot.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
    startActivity(intentStartRoot);
}

解决方案

This is probably a bug in the Android Framework. I tested on about 12 devices today and noticed that this bug occurs reliably on Nexus-type devices running these versions of Android:

4.4.4 5.0.1 5.0.2

Interestingly, Samsung devices running the same versions of Android do not exhibit the problem. Android 5.1 and later seems to be better in that I see no more ANRs in com.android.launcher; however I am now seeing ANRs in com.google.android.googlequicksearchbox.

I worked around this problem after noticing that my Activity was overriding onBackPressed() without invoking super.onBackPressed(). After I added super.onBackPressed(), the ANRs went away. But this is not a full workaround because calling super.onBackPressed() finished my Activity, which I do not want.

I hope this helps someone.

See: Using FLAG_ACTIVITY_REORDER_TO_FRONT to switch among persistently running UI activities leads to "no window focus" error

See: Android-L issue: onBackpressed when using FLAG_ACTIVITY_REORDER_TO_FRONT to launch previous activity & freezes app for sometime

Also, I found a bug entry on Google's site that seems related: https://code.google.com/p/android/issues/detail?id=91534