gpt4 book ai didi

android - 从后台恢复 Android 应用程序后,它卡住了

转载 作者:行者123 更新时间:2023-11-29 00:07:38 24 4
gpt4 key购买 nike

问题

我按下主页按钮,当我从启动图标重新打开应用程序时,我失去了部分布局,一切都卡住了。我仍然可以使用 android 界面(主页按钮等)

背景状态之前

enter image description here

卡住

enter image description here

如果你需要的话,这是这个。

enter image description here

OnResume 方法

@Override
protected void onResume() {

super.onResume();
setContentView(R.layout.main);


}

创建时

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

INSTANCE = this;

Constants.initializeConstantsFromResources(this);

Controller.getInstance().setPreferences(PreferenceManager.getDefaultSharedPreferences(this));

if (Controller.getInstance().getPreferences().getBoolean(Constants.PREFERENCES_SHOW_FULL_SCREEN, false)) {
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
}

if (Controller.getInstance().getPreferences().getBoolean(Constants.PREFERENCES_GENERAL_HIDE_TITLE_BARS, true)) {
requestWindowFeature(Window.FEATURE_NO_TITLE);
}

setProgressBarVisibility(true);

setContentView(R.layout.main);

mCircularProgress = getResources().getDrawable(R.drawable.spinner);

EventController.getInstance().addDownloadListener(this);

mHideToolbarsRunnable = null;

mInflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);

buildComponents();

mViewFlipper.removeAllViews();

updateSwitchTabsMethod();
updateBookmarksDatabaseSource();

registerPreferenceChangeListener();

Intent i = getIntent();
if (i.getData() != null) {
// App first launch from another app.
addTab(false);
navigateToUrl(i.getDataString());
} else {
// Normal start.
int currentVersionCode = ApplicationUtils.getApplicationVersionCode(this);
int savedVersionCode = PreferenceManager.getDefaultSharedPreferences(this).getInt(Constants.PREFERENCES_LAST_VERSION_CODE, -1);

// If currentVersionCode and savedVersionCode are different, the application has been updated.
if (currentVersionCode != savedVersionCode) {
// Save current version code.
Editor editor = PreferenceManager.getDefaultSharedPreferences(this).edit();
editor.putInt(Constants.PREFERENCES_LAST_VERSION_CODE, currentVersionCode);
editor.commit();

// Display changelog dialog.
Intent changelogIntent = new Intent(this, ChangelogActivity.class);
startActivity(changelogIntent);
}

boolean lastPageRestored = false;
// gaf - comienzo con la pagina inicial
String savedUrl = "file:///android_asset/startpage/index.html";
//String savedUrl = "http://servidor-cade.com";
//String savedUrl = "http://192.168.1.18:3636";
addTab(false);
navigateToUrl(savedUrl);
lastPageRestored = false;



}

initializeWebIconDatabase();

startToolbarsHideRunnable();
}

最佳答案

首先:

setContentView(R.layout.main);

应该在:

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

第二:不要在 OnResume 上设置 setContentView(R.layout.main);。 bundle 将保存状态。删除该行。

当您恢复应用程序时,布局会再次显示(甚至可能覆盖当前布局)。

第三:你的代码不干净,组织也不好。例如:检查当前版本以显示更改日志应该在 setContentView(R.layout.main); 之后(遵循“First”)

编辑您的onCreate 应该是这样的:

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

Constants.initializeConstantsFromResources(this);

Controller.getInstance().setPreferences(PreferenceManager.getDefaultSharedPreferences(this));

if (Controller.getInstance().getPreferences().getBoolean(Constants.PREFERENCES_SHOW_FULL_SCREEN, false)) {
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
}

if (Controller.getInstance().getPreferences().getBoolean(Constants.PREFERENCES_GENERAL_HIDE_TITLE_BARS, true)) {
requestWindowFeature(Window.FEATURE_NO_TITLE);
}
setContentView(R.layout.main);

关于android - 从后台恢复 Android 应用程序后,它卡住了,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32720027/

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