gpt4 book ai didi

java - 窗口 View 泄露

转载 作者:行者123 更新时间:2023-12-02 10:44:48 26 4
gpt4 key购买 nike

public class ProgressCircleActivity extends AppCompatActivity {

private ProgressDialog progressBar;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.progress_circle_activity);
progressBar = new ProgressDialog(ProgressCircleActivity.this);
progressBar.setMessage("Please wait ...");
progressBar.setCancelable(true);
progressBar.setProgressStyle(ProgressDialog.STYLE_SPINNER);
progressBar.setProgress(0);
progressBar.setMax(100);
progressBar.show();

new Thread(new Runnable() {
@Override
public void run() {
try {
Thread.sleep(3*1000);
Intent i=new Intent(ProgressCircleActivity.this,PhoneNumberLogin.class);
startActivity(i);
//Remove activity
finish();
} catch (InterruptedException e) {
e.printStackTrace();
}
progressBar.dismiss();
}
}).start();
}
}

这是我的日志

10-05 16:12:22.577 27797-27797/? E/SELinux: [DEBUG] get_category: variable seinfo: default sensitivity: NULL, cateogry: NULL
10-05 16:12:32.397 27797-27797/com.example.dis015.meetdax2danish E/WindowManager: android.view.WindowLeaked: Activity com.example.dis015.meetdax2danish.ProgressCircleActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView{25b6bc4a V.E..... R......D 0,0-501,174} that was originally added here
at android.view.ViewRootImpl.<init>(ViewRootImpl.java:520)
at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:287)
at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:91)
at android.app.Dialog.show(Dialog.java:325)
at com.example.dis015.meetdax2danish.ProgressCircleActivity.onCreate(ProgressCircleActivity.java:25)
at android.app.Activity.performCreate(Activity.java:6575)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1134)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3143)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3300)
at android.app.ActivityThread.access$1000(ActivityThread.java:211)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1705)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:145)
at android.app.ActivityThread.main(ActivityThread.java:6946)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1404)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1199)

这是我的splashScreenActivity,当我打开应用程序时,该应用程序崩溃了。但在某些手机中,该应用程序没有崩溃。我不知道问题是什么,请帮我解决

最佳答案

您没有关闭进度条,因此它显示了泄漏的窗口消息。
在完成 Activity 之前,请关闭进度栏对话框。

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.progress_circle_activity);
progressBar = new ProgressDialog(ProgressCircleActivity.this);
progressBar.setMessage("Please wait ...");
progressBar.setCancelable(true);
progressBar.setProgressStyle(ProgressDialog.STYLE_SPINNER);
progressBar.setProgress(0);
progressBar.setMax(100);
progressBar.show();

new Thread(new Runnable() {
@Override
public void run() {
try {
Thread.sleep(3*1000);
Intent i=new Intent(ProgressCircleActivity.this,PhoneNumberLogin.class);
startActivity(i);//dismiss the progressdialog
progressBar.dismiss();
//Remove activity
finish();
} catch (InterruptedException e) {
e.printStackTrace();
}

}
}).start();
}

关于java - 窗口 View 泄露,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52664083/

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