开发者

Application going into ANR mode

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

  1. User starts the application - Activity shows up
  2. User presses back button
  3. User re-starts the application. At this point application just shows a blank screen, none of the buttons(home/back) respond, after some time Force-close dialog comes up.

    NOTE: If the user presses "Home" and then relaunches the app, this doesn't happen, only if the user presses "Back" and then relaunches it.

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.

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

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

EDIT: 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


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

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?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜