问题
我按下主页按钮,当我从启动图标重新打开应用程序时,我松开了部分布局,一切都冻结了。我仍然可以使用android界面(homebutton等)
在背景状态之前
冷冻
如果需要,可以使用以下内容。
OnResume方法
@Override
protected void onResume() {
super.onResume();
setContentView(R.layout.main);
}
OnCreate中
@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();
}
答案 0 :(得分:2)
首先:
setContentView(R.layout.main);
应该在以后:
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
第二:不要在你的OnResume上设置setContentView(R.layout.main);
。捆绑将拯救国家。删除该行。
当您恢复应用时,布局会再次显示(甚至可能会显示当前的布局)。
第三:你的代码不干净,也没有很好的组织。例如:检查当前版本以显示更改日志应在setContentView(R.layout.main);
之后(按照"第一")
编辑您的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);