这是我的java代码
@Override
protected void onDestroy() {
int i;
super.onDestroy();
if (bitmapList != null) {
for (i = INDEX_COLLAGE; i < bitmapList.length; i += INDEX_COLLAGE_BACKGROUND) {
if (bitmapList[i] != null) {
bitmapList[i].recycle();
}
}
}
if (collageView != null) {
if (collageView.shapeLayoutList != null) {
for (i = INDEX_COLLAGE; i < collageView.shapeLayoutList.size(); i += INDEX_COLLAGE_BACKGROUND) {
for (int j = INDEX_COLLAGE; j < collageView.shapeLayoutList.get(i).shapeArr.length; j += INDEX_COLLAGE_BACKGROUND) {
if (collageView.shapeLayoutList.get(i).shapeArr[j] != null) {
collageView.shapeLayoutList.get(i).shapeArr[j].freeBitmaps();
}
}
}
}
if (collageView.maskBitmapArray != null) {
for (i = INDEX_COLLAGE; i < collageView.maskBitmapArray.length; i += INDEX_COLLAGE_BACKGROUND) {
if (collageView.maskBitmapArray[i] != null) {
if (!collageView.maskBitmapArray[i].isRecycled()) {
collageView.maskBitmapArray[i].recycle();
}
collageView.maskBitmapArray[i] = null;
}
}
}
}
if (adWhirlLayout != null) {
adWhirlLayout.removeAllViews();
adWhirlLayout.destroy();
}
}
private void backButtonAlertBuilder() {
AlertDialog.Builder builder = new AlertDialog.Builder(CreateCollageActivity.this);
builder.setMessage("Would you like to save image ?").setCancelable(true).setPositiveButton("Yes", new OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
if (analytics != null)
analytics.logEvent(Analytics.Param.IMAGE_SAVE, "");
new SaveImageTask().execute();
}
}).setNeutralButton("No", new OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
finish();
}
});当我单击上一次button..when时,该应用程序崩溃,我调试了它显示的代码java.lang.RuntimeException:无法销毁activity和java.lang.RuntimeException
发布于 2020-11-09 11:17:08
您应该在super.onDestroy()之前编写所有代码;使这一行成为该方法的最后一条语句。
发布于 2020-11-09 10:43:04
只需用onBackPressed()替换onDestroy()方法
@Override
public void onBackPressed() {
super.onBackPressed();
},所以您的代码将类似于那个
@Override
protected void onBackPressed() {
int i;
super.onBackPressed();
if (bitmapList != null) {
for (i = INDEX_COLLAGE; i < bitmapList.length; i += INDEX_COLLAGE_BACKGROUND) {
if (bitmapList[i] != null) {
bitmapList[i].recycle();
}
}
}
if (collageView != null) {
if (collageView.shapeLayoutList != null) {
for (i = INDEX_COLLAGE; i < collageView.shapeLayoutList.size(); i += INDEX_COLLAGE_BACKGROUND) {
for (int j = INDEX_COLLAGE; j < collageView.shapeLayoutList.get(i).shapeArr.length; j += INDEX_COLLAGE_BACKGROUND) {
if (collageView.shapeLayoutList.get(i).shapeArr[j] != null) {
collageView.shapeLayoutList.get(i).shapeArr[j].freeBitmaps();
}
}
}
}
if (collageView.maskBitmapArray != null) {
for (i = INDEX_COLLAGE; i < collageView.maskBitmapArray.length; i += INDEX_COLLAGE_BACKGROUND) {
if (collageView.maskBitmapArray[i] != null) {
if (!collageView.maskBitmapArray[i].isRecycled()) {
collageView.maskBitmapArray[i].recycle();
}
collageView.maskBitmapArray[i] = null;
}
}
}
}
if (adWhirlLayout != null) {
adWhirlLayout.removeAllViews();
adWhirlLayout.destroy();
}
}
private void backButtonAlertBuilder() {
AlertDialog.Builder builder = new AlertDialog.Builder(CreateCollageActivity.this);
builder.setMessage("Would you like to save image ?").setCancelable(true).setPositiveButton("Yes", new OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
if (analytics != null)
analytics.logEvent(Analytics.Param.IMAGE_SAVE, "");
new SaveImageTask().execute();
}
}).setNeutralButton("No", new OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
finish();
}
});https://stackoverflow.com/questions/64749860
复制相似问题