解决卡顿问题

This commit is contained in:
2025-12-24 21:39:01 +08:00
parent 2137d71c1f
commit 75d1165ee8
14 changed files with 60 additions and 652 deletions
@@ -9,6 +9,10 @@ import android.os.Bundle;
import android.webkit.WebView;
public class PrivacyActivity extends Activity implements DialogInterface.OnClickListener {
// WebView 和 Dialog 引用,用于资源管理
private WebView webView;
private AlertDialog privacyDialog;
// 隐私协议内容
final String privacyContext = "<html><body style='padding:16px;font-size:14px;line-height:1.8;'>" +
"<h3>提示</h3>" +
@@ -44,15 +48,16 @@ public class PrivacyActivity extends Activity implements DialogInterface.OnClick
// 显示隐私协议对话框
private void ShowPrivacyDialog() {
WebView webView = new WebView(this);
webView = new WebView(this);
webView.loadData(privacyContext, "text/html", "utf-8");
AlertDialog.Builder privacyDialog = new AlertDialog.Builder(this);
privacyDialog.setCancelable(false);
privacyDialog.setView(webView);
privacyDialog.setTitle("隐私政策");
privacyDialog.setNegativeButton("拒绝", this);
privacyDialog.setPositiveButton("同意", this);
privacyDialog.create().show();
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setCancelable(false);
builder.setView(webView);
builder.setTitle("隐私政策");
builder.setNegativeButton("拒绝", this);
builder.setPositiveButton("同意", this);
privacyDialog = builder.create();
privacyDialog.show();
}
@Override
@@ -89,4 +94,39 @@ public class PrivacyActivity extends Activity implements DialogInterface.OnClick
SharedPreferences prefs = this.getSharedPreferences("PlayerPrefs", MODE_PRIVATE);
return prefs.getBoolean("PrivacyAcceptedKey", false);
}
@Override
protected void onPause() {
super.onPause();
// 暂停 WebView 以节省资源
if (webView != null) {
webView.onPause();
}
}
@Override
protected void onResume() {
super.onResume();
// 恢复 WebView
if (webView != null) {
webView.onResume();
}
}
@Override
protected void onDestroy() {
super.onDestroy();
// 关闭对话框
if (privacyDialog != null && privacyDialog.isShowing()) {
privacyDialog.dismiss();
privacyDialog = null;
}
// 显式销毁 WebView 释放资源,防止内存泄漏
if (webView != null) {
webView.onPause();
webView.removeAllViews();
webView.destroy();
webView = null;
}
}
}