gpt4 book ai didi

android - Activity 不会破坏以在 android 中释放堆?

转载 作者:行者123 更新时间:2023-11-30 03:15:00 25 4
gpt4 key购买 nike

我试图通过销毁当前 Activity 来释放堆大小,同时转到另一个 Activity 。

我在 backPreess() 上使用 finish();

但这并没有释放堆。

on setContentView()

堆大小增加了 16Mb。我想在进行另一项 Activity 后释放堆中的这种增加。任何人都可以帮助如何做到这一点?

我的代码如下:

    package com.stancil.levels;        
public class PaintActivity extends ZebraActivity implements
PaintView.LifecycleListener, PaintView1.LifecycleListener1 {

private static final int REQUEST_PICK_COLOR = 1;

....
....
public PaintActivity() {
_state = new State();
}

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

Constants.context = getApplicationContext();


setContentView(R.layout.paint);
..................
...................
...............

}


public void onPreparedToLoad() {
// We need to invoke InitPaintView in a callback otherwise
// the visibility changes do not seem to be effective.
new Handler() {
@Override
public void handleMessage(Message m) {
new InitPaintView();

Log.v("PaintActivity", "After InitPaintView Called");
}
}.sendEmptyMessage(0);
}


private class InitPaintView implements Runnable {
private Bitmap _originalOutlineBitmap;
private Handler _handler;

public InitPaintView() {
// Make the progress bar visible and hide the view

_paintView.setVisibility(View.GONE);
_progressBar.setProgress(0);
_progressBar.setVisibility(View.VISIBLE);
_state._savedImageUri = null;
_state._loadInProgress = true;

_originalOutlineBitmap=_imageBitmap;
_handler = new Handler() {
@Override
public void handleMessage(Message m) {
switch (m.what) {
case Progress.MESSAGE_INCREMENT_PROGRESS:
// Update progress bar.
_progressBar.incrementProgressBy(m.arg1);
break;
case Progress.MESSAGE_DONE_OK:
case Progress.MESSAGE_DONE_ERROR:
// We are done, hide the progress bar
// the paint view back on.
_state._loadInProgress = false;
_paintView.setVisibility(View.VISIBLE);
_progressBar.setVisibility(View.GONE);
initiatePopupWindow();
break;
}
}
};

new Thread(this).start();

}

public void run() {
Log.v("Wasimmmmmmmmmmmmmmmm", "qqqqq 22");
_paintView.loadFromBitmap(_originalOutlineBitmap, _handler);
}

}



private static class State {
// Are we just loading a new outline?
public boolean _loadInProgress;

// The resource ID of the outline we are coloring.
//public int _loadedResourceId;
//
// If we have already saved a copy of the image, we store the URI here
// so that we can delete the previous version when saved again.
public Uri _savedImageUri;
}







@Override
public void onBackPressed() {
new AlertDialog.Builder(this)
.setTitle("Exit")
.setMessage("Do you want to go to Main Menu?")
.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {

Constants.check_new=true;
Intent i=new Intent(PaintActivity.this,MainActivity.class);
// i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(i);
finish();
overridePendingTransition(R.anim.fade_in, R.anim.fade_out);

}
}).setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
// Do nothing.
}
}).show();
}
}

}

最佳答案

在 onDestroy 方法中释放 yoru 对象,无论如何,如果没有对被销毁 Activity 的引用,GC 将在需要时自动清理(它不需要在您关闭 Activity 后立即发生)。或者,有一种方法可以强制运行 GC,但我什至不会写它,因为它不是典型应用程序应该使用的真正特性

关于android - Activity 不会破坏以在 android 中释放堆?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20285340/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com