作者:sdfasdfqg | 来源:互联网 | 2024-10-12 15:33
Myapplicationgetskilledeachtimethatitcomesbackfromthescreen-off-state.Ifetchallthei
My application gets killed each time that it comes back from the screen-off-state. I fetch all the information that my app does, but I can't find out why it calls onDestroy. It's the first time I'm seeing this behavior in my applications.
每次从屏幕关闭状态返回时,我的应用程序都会被杀死。我获取了我的应用程序所做的所有信息,但我无法找到它调用onDestroy的原因。这是我第一次在我的应用程序中看到这种行为。
My main activity extends tabActivity because it contains a tabhost. I've read that it has to extend it or it will FC. I'm not sure if my issue is related to this?! Oh and it implements Observer but this should be no problem.
我的主要活动扩展了tabActivity,因为它包含tabhost。我已经读过它必须扩展它或它将FC。我不确定我的问题是否与此有关?!哦,它实现了Observer,但这应该没问题。
Here are the logs:
这是日志:
07-21 09:57:53.247: VERBOSE/###(13180): onResume
07-21 09:57:53.267: VERBOSE/###(13180): onPause
07-21 09:57:59.967: VERBOSE/###(13180): onResume
07-21 09:58:00.597: VERBOSE/###(13180): onPause
07-21 09:58:00.597: VERBOSE/###(13180): onDestroy
07-21 09:58:00.637: VERBOSE/###(13180): onCreate
The crazy thing is that it calls the onDestroy the most times after the screen goes on again, and sometimes it has enough time to do this before the screen goes off. But after it goes on again it does the same again...
疯狂的是,它在屏幕再次亮起后最多调用onDestroy,有时它有足够的时间在屏幕关闭之前执行此操作。但在它再次发生之后它再次发生了同样的事情......
I hope that someone has a tip for me or any information on how to resolve this issue.
我希望有人给我一个提示或任何有关如何解决此问题的信息。
I'm not sure if this is important, but I use the android 2.1-update1 sdk for my application.
我不确定这是否重要,但我使用android 2.1-update1 sdk作为我的应用程序。
EDIT:
The application gets tested on a real Android Device.
该应用程序在真正的Android设备上进行测试。
Here is some basic code with all unnecessary lines and information removed:
以下是一些基本代码,其中删除了所有不必要的行和信息:
package;
imports;
public class WebLabActivity extends TabActivity implements Observer{
#declerations
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Log.v("###", "onCreate");
setContentView(R.layout.main);
# initialize some basic things
}
@Override
public void onResume() {
super.onResume();
Log.v("###", "onResume");
}
@Override
public void onDestroy() {
super.onDestroy();
Log.v("###", "onDestroy");
}
@Override
public void onRestart() {
Log.v("###", "onRestart");
super.onRestart();
}
@Override
public void onPause() {
Log.v("###", "onPause");
super.onPause();
}
@Override
public void onConfigurationChanged(Configuration newConfig) {
Log.v("###", "onConfigurationChanged");
super.onConfigurationChanged(newConfig);
}
@Override
public void update(Observable observable, Object data) {
Log.v("###", "notifyManager.getWho() + " made an Update");
}
private void initializeSidebarTabhost() {
TabSpec 1 = tabHost.newTabSpec("1");
TabSpec 2 = tabHost.newTabSpec("2");
TabSpec 3 = tabHost.newTabSpec("3");
TabSpec 4 = tabHost.newTabSpec("4");
1.setIndicator("###");
2.setIndicator("###");
3.setIndicator("###");
4.setIndicator("###");
addIntents
tabHost.addTab(1); //0
tabHost.addTab(2); //1
tabHost.addTab(3); //2
tabHost.addTab(4); //3
tabHost.getTabWidget().setCurrentTab(2);
}
}
EDIT2:
Ok, I've tested my application without initializing anything, then with only extending activity, or without implementing observer, but my changes had no effect. Every time I set my phone to sleep, then wake it up, onDestroy()
get's called?!
好的,我已经测试了我的应用程序而没有初始化任何东西,只有扩展活动,或者没有实现观察者,但我的更改没有任何效果。每次我将手机设置为睡眠状态,然后将其唤醒,onDestroy()将其调用?!
EDIT3:
Ok, I found out something interesting.
好的,我发现了一些有趣的东西。
First here's my AndroidManifest.xml
首先是我的AndroidManifest.xml
As soon as I remove the screenOrientation="landscape"
, the application won't be destroyed each time that I wake up my device. I tried it more than 10 times but no more calls to onDestroy()
一旦我删除screenOrientation =“landscape”,每次唤醒我的设备时都不会销毁应用程序。我尝试了10次以上但没有更多的调用onDestroy()
So I think that I will have to set this in code?! Any tips or pieces of code?
所以我认为我必须在代码中设置它?!任何提示或代码片段?
3 个解决方案