申请进入ANR模式模式、ANR

2023-09-07 12:30:56 作者:祖国滴粑粑花

当用户presses在我的应用程序中的后退按钮。下面是这种情况:

When the users presses the back button in my application. Here is the scenario:

用户启动应用程序 - 活动显示出来用户presses后退按钮用户重新启动应用程序。 在这一点上应用只是显示一个空白屏幕,没有一个按键(家庭/后)反应,后一段时间后强制关闭对话框出现。结果注意:如果用户presses家,然后将重新启动应用程序,这不会发生,只有当用户presses返回,然后重新推出它

在我的onCreate()我有一些网络设置code。然而,的onDestroy()有相应的清理code,所以我不明白为什么会这样。

In my onCreate() I have some network setup code. However, onDestroy() has the corresponding cleanup code, so I don't understand why this is happening.

@Override
public void onCreate(Bundle savedInstanceState) {
    Log.d(DEBUG_TAG, "onCreate()");
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

     // Aquire the multicast lock
     // Create an instance of JmDNS
     // Add a listener for Bonjour services of a given type 
}

@Override
protected void onDestroy() {
    Log.d(DEBUG_TAG, "onDestroy()");
     // Remove the services listener 
     // Set the reference to JmDNS instance null
     // Release the multicast lock
    super.onDestroy();
}

不知道是怎么回事,不知道如何调试这一点。

Not sure what is going on, and don't know how to debug this.

有趣的是 - 零配置浏览器流行的应用程序,我从Android Market下载使用调试雷 - 似乎有同样的问题。

Interestingly - "Zeroconf Browser" a popular app that I downloaded from Android Market to use to debug mine - seems to have the same issue.

编辑:改变了code从调用onStart()/的onStop()来的onCreate()/的onDestroy()。同样的问题和以前一样。

Changed the code from onStart()/onStop() to onCreate()/onDestroy(). Same problem as before.

编辑:对于谁在类似的问题上运行任何人,这是什么导致我的痛苦。 Android的code是不是罪魁祸首:http://sourceforge.net/tracker/index.php?func=detail&aid=2933183&group_id=93852&atid=605791

For anyone who runs in a similar problem, this is what was causing my misery. Android code wasn't the culprit: http://sourceforge.net/tracker/index.php?func=detail&aid=2933183&group_id=93852&atid=605791

推荐答案

您可能会使得UI线程网络请求。你可能检出无痛线程并的 AsyncTask的用于处理。

You may be making network requests on the UI thread. You might checkout Painless Threading and AsyncTask for handling that.

请注意,这可能是一个好主意,做您的安装和拆卸的的onCreate 的onDestroy 在onStart 可活动的的生命周期;是你的code防范这种情况?

Note that it might be a good idea to do your setup and tear-down in onCreate and onDestroy. onStart can be called multiple times during the activity's life cycle; is your code guarding against this case?