在调查我们应用程序中的内存问题时,事实证明,如果应用程序 Activity 是 MapActivity,它的第一个实例将不会最终确定。导致其他内存泄漏,例如传递给 setContentView 的视图。
以前有人注意到吗?
这是测试代码,显示“MainActivity:1”尚未最终确定,而 MainActivity 继承自 Activity。
要进行测试,需要多次更改设备或仿真器方向。
import com.google.android.maps.MapActivity;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
public class MainActivity extends MapActivity {
private static final String defaultTag = "MA";
private static final boolean isDebugModeActivate = true;
private static final boolean isClassTagDisplayed = false;
private static final boolean isWebModeActivate = false;
static public void d(Object thiso, String message)
{
String tag = defaultTag + (isClassTagDisplayed == true ? "_" + thiso.getClass().getSimpleName() : "");
message = (isClassTagDisplayed == false ? thiso.getClass().getSimpleName() + " : " : "") + message;
Log.d(tag, message);
}
public MainActivity()
{
counter++;
uid++;
id = uid;
d(this, id + " tst constructor (" + counter + ")");
}
private static int counter = 0;
private static int uid = 0;
private final int id;
protected void finalize() throws Throwable
{
counter--;
d(this, id + " tst finalize (" +counter + ") ");
super.finalize();
}
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
@Override
protected boolean isRouteDisplayed()
{
return false;
}
}
谢谢你,大卫