本文介绍了难道的onDestroy()或结束()实际上杀活动?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

其实我知道我是问关于Android的简单和基本的概念。但我有点困惑,这些完成()的onDestroy()的方法。这是否会杀了活动,并释放与这些活动相关的资源?

Actually I know i am asking about the simple and basic concept of Android. But I am a little bit confused about these finish() and onDestroy() methods.Whether this will kill the activity and free the resources associated with these activity?

我试图用一个简单的应用程序,它仅包含一个活性。我觉得这个概念就像是当应用程序运行时,该活动将启动。当我们点击后退按钮,它就会完成。而我给了内部的每个生命周期方法的一些吐司消息知道内存使用情况。而当我点击后退按钮就执行的onPause()的onStop()的onDestroy()。我觉得这个活动结束了。但是,当我再次重新启动的应用程序,然后花了更多的内存比previous时间。出现这种情况,每次当我从Eclipse运行应用程序或重新启动,从主屏幕上的应用程序。

I tried with a simple application which contains only one activity. I thought the concept is like When the application runs, the activity will start. and when we click on back button, it will finish. And I gave some toast message inside each life cycle methods for knowing the memory usage . And when I clicked on the back button it executed onPause(), onStop(), and onDestroy(). I thought this activity finished. But when i relaunched the application again, then it took more memory than the previous time. This happens every time when I run the app from eclipse or relaunch the application from home screen.

为什么会发生?我怎样才能真正破坏应用程序/活动,以释放内存?

Why is it happening? How can i actually destroy the application / activity to free the memory?

我包括我的code。我只是给了类中唯一一个敬酒的消息。然后也内存使用量增加。

I am including my code. I just give only one toast message inside the class. Then also memory usage is increasing.

每个当我运行的应用程序分配的规模在不断扩大如时间:3302744,3442384,3474552

Each time when I run the application the allocated size is increasing like : 3302744, 3442384, 3474552

 public class myActivity extends Activity
   {
         @Override
         public void onCreate(Bundle savedInstanceState)
         {
             super.onCreate(savedInstanceState);
        Toast.makeText(getBaseContext()," allocated size  = " + Debug.getNativeHeapAllocatedSize(), 1).show();
         }

   }

清单:

<application android:icon="@drawable/icon" android:label="@string/app_name">
        <activity android:name=".myActivity "
                  android:label="@string/app_name"  >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
 </application>

为什么内存增加每次?

Why is the memory increasing every time?

推荐答案

终点()杀死活性,释放内存......除非你有一定的参考存储被泄漏...例如像onRetainNonConfigurationInstance方法()

The finish() kills the activity and releases memory... unless you have some reference stored that is leaked... for example on methods like onRetainNonConfigurationInstance()

在preSS后退按钮所谓的终点()方法,该方法比调用的onPause,的onStop,的onDestroy。

When you press the back button what is called is the finish() method that than calls onPause, onStop, onDestroy.

这篇关于难道的onDestroy()或结束()实际上杀活动?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 21:40