的onDestroy被称为每个屏幕的推移时间 [英] onDestroy gets called each time the screen goes on

查看:168
本文介绍了的onDestroy被称为每个屏幕的推移时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序获取每个它来自关屏状态回来时被杀。我获取所有的我的应用程序确实的资料,但我不能找出为什么它调用的onDestroy。这是第一次我看到在我的应用程序这种行为。

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.

我的主要活动来延长tabActivity,因为它包含一个tabhost。我读过,它已经扩展它或将FC。我不知道如果我的问题是有关这个?哦,它实现了观察员,但这个应该是没有问题的。

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.

下面是日志:

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

疯狂的事情是,它调用的onDestroy最次后屏幕会再次打开,而且它也有足够的时间来做到这一点之前,屏幕熄灭。但经过如此下去一次它又一次一样...

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...

我希望有人有一个提示,我还是如何解决这个问题的任何信息。

I hope that someone has a tip for me or any information on how to resolve this issue.

我不知道这是很重要的,但是我用的是Android 2.1系统,UPDATE1 SDK我的应用程序。

I'm not sure if this is important, but I use the android 2.1-update1 sdk for my application.

编辑:

应用程序获取一个真正的Andr​​oid设备进行测试。

The application gets tested on a real Android Device.

下面是一些基本的code与所有不必要的行和信息删除:

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:

好了,我已经没有任何初始化只延长活性测试我的应用程序,然后,或不执行观测,但我的变化没有任何影响。每当我把我的手机睡觉,然后唤醒它,的onDestroy()获取叫?!

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?!

EDIT3:

好吧,我发现了一些有趣的事情。

Ok, I found out something interesting.

首先,这里是我的Andr​​oidManifest.xml

First here's my AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.tundem.###"
      android:versionCode="1"
      android:versionName="1.0">
    <uses-sdk android:minSdkVersion="7" />

    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

    <application android:icon="@drawable/icon" android:label="@string/app_name">
        <activity android:name=".###" android:label="@string/app_name" android:screenOrientation="landscape" android:theme="@android:style/Theme.Light.NoTitleBar">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>
</manifest>

当我删除 screenOrientation =景观,应用程序不会每次我每天早上起来我的设备时被毁。我尝试了超过10次,但没有更多的调用的onDestroy()

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()

所以,我认为我将不得不设置这个在code?的code任何提示或块?

So I think that I will have to set this in code?! Any tips or pieces of code?

推荐答案

如果你希望停止破坏/创建问题,这是因为在一个方向的方向变化和锁的默认的Andr​​oid,那么你需要添加的 code和XML

If you want to stop the destroy/create issue that is the default in android because of an orientation change and lock in one orientation then you need to add code and xml

在你activites code(有关XML注释)

In your activites code (notes about the xml)

    // When an android device changes orientation usually the activity is destroyed and recreated with a new 
    // orientation layout. This method, along with a setting in the the manifest for this activity
    // tells the OS to let us handle it instead.
    //
    // This increases performance and gives us greater control over activity creation and destruction for simple 
    // activities. 
    // 
    // Must place this into the AndroidManifest.xml file for this activity in order for this to work properly 
    //   android:configChanges="keyboardHidden|orientation"
    //   optionally 
    //   android:screenOrientation="landscape"
    @Override
    public void onConfigurationChanged(Configuration newConfig) 
    {
        super.onConfigurationChanged(newConfig);
    }

这篇关于的onDestroy被称为每个屏幕的推移时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆