【问题标题】:Force onDestroy to solve memory problems强制 onDestroy 解决内存问题
【发布时间】:2012-07-30 12:36:53
【问题描述】:

我的应用程序遇到内存问题,它使用 TabHost 和 TabGroupActivity 作为 TabContent。

我注意到有时候Activity的生命周期很奇怪。

我启动应用程序,加载了 tab1,然后单击 tab2 (Tab1->Tab2 )

Tab1Group.onPause called
Tab1.onPause called

Tab2Group.onCreate called
Tab2.onCreate called

然后我回到Tab1(Tab2->Tab1)

Tab2Group.onPause called 
Tab1Group.onDestroy called
Tab1.onDestroy called
Tab1.onCreate called

好吧,如果我回来的时候tab1被销毁了,直接销毁而不是调用onPause就好了,这样VM可以释放更多内存。

你怎么看?

【问题讨论】:

    标签: android android-activity lifecycle android-sdk-2.3


    【解决方案1】:

    清除所有意图并手动清空所有对象

    Intent intent = new Intent(Intent.ACTION_MAIN);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    intent.addCategory(Intent.CATEGORY_HOME); 
    startActivity(intent);
    

    【讨论】:

    • 不确定我该怎么做.. 我使用的是 tabhost,所以我没有调用 startActivity
    • 我发现这是解决方案 @Override public void onConfigurationChanged(Configuration newConfig) { super.onConfigurationChanged(newConfig); }
    猜你喜欢
    • 2012-08-19
    • 2010-12-11
    • 2012-05-23
    • 1970-01-01
    • 2022-06-28
    • 1970-01-01
    • 2021-10-19
    • 2011-05-28
    相关资源
    最近更新 更多