题
当用户按下我的应用程序中的后退按钮时。这是场景:
- 用户启动应用程序 - 活动 显示
- 用户按压按钮
- 用户重新启动应用程序。 在此点应用程序只显示一个空白屏幕,没有按钮(家庭/返回)响应,之后
一些时间的力度关闭对话。
注意:如果用户按“主页”然后重新启动应用程序,则才会发生这种情况,只有当用户按“返回”然后重新启动它。在我的oncreate()中我有一些网络设置代码。但是,ondestroy()有相应的清理代码,所以我不明白为什么发生这种情况。
.@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(); }
不确定发生了什么,并不知道如何调试这一点。 有趣的是 - “zeroconf浏览器”我从Android Market下载以便调试的流行应用程序矿山 - 似乎有同样的问题。
编辑:将代码从onstart()/ onstop()更改为OnCreate()/ ondestroy()。与以前一样的问题。
编辑:对于在类似问题中运行的人来说,这就是导致我痛苦的原因。 Android代码不是罪魁祸首: http://sourceforge.net/tracker/index.php?func=细节& 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?
不隶属于 StackOverflow