av一区二区在线观看_亚洲男人的天堂网站_日韩亚洲视频_在线成人免费_欧美日韩精品免费观看视频_久草视

您的位置:首頁(yè)技術(shù)文章
文章詳情頁(yè)

android - 單activity+多fragment場(chǎng)景,應(yīng)用長(zhǎng)時(shí)間在后臺(tái)進(jìn)入前臺(tái)時(shí),fragment全部是空白

瀏覽:184日期:2024-08-30 11:50:55

問(wèn)題描述

1,問(wèn)題: 應(yīng)用長(zhǎng)期在后臺(tái)的場(chǎng)景下,進(jìn)入前臺(tái)時(shí),fragment顯示為空白2,app框架大體實(shí)現(xiàn): 1個(gè)activity+多個(gè)Fragment,使用的是add()方法以及 hide(),show()方法,顯示fragment3,相關(guān)代碼:

onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // 判斷 savedInstanceState是否為空: setCanResizeWindow(false); maskView = new View(getApplicationContext()); maskView.setBackground(new ColorDrawable(Color.parseColor('#30000000'))); maskView.setClickable(true); maskView.setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View v) { removeMask();} }); setContentView(R.layout.activity_home); EventBus.getDefault().register(this); //3,個(gè)推 PushManager.getInstance().initialize(getApplicationContext()); initView(savedInstanceState); getUserData(); getDataFromMsgBrief();} private void initView(Bundle savedInstanceState) {mBottomDial = (LinearLayout) findViewById(R.id.btn_Dial);mBottomComm = (LinearLayout) findViewById(R.id.btn_comm);mBottomContact = (LinearLayout) findViewById(R.id.btn_contact);mBottomLife = (LinearLayout) findViewById(R.id.btn_life);mBottomDialIv = (ImageView) findViewById(R.id.tab_dial_image);mBottomDiaTv = (TextView) findViewById(R.id.tab_dial_text);mSmsIV = (SmsImageView) findViewById(R.id.siv_sms_icon_homeact);//第一次登錄系統(tǒng)時(shí),修改數(shù)據(jù)庫(kù)的Istravelrely字段if (!SpUtils.getSynDB(getApplicationContext())) { ThreadPoolUtil.getmExecutor().execute(new Runnable() {@Overridepublic void run() { CopyLocalContactsUtils.checkIsTravelRely(getApplication()); SpUtils.setSynDB(getApplicationContext());} });}//初始化mBottomDial為選中狀態(tài),fl_content填充DialFragmentmBottomDial.setSelected(true);//if (savedInstanceState != null) {// LogUtils.d('HomeActivity savedInstanceState != null');//// Fragment dialFragment = getSupportFragmentManager().findFragmentByTag(DIAL_TAG);// Fragment contactFragment = getSupportFragmentManager().findFragmentByTag(CONTACT_TAG);// Fragment commFragment = getSupportFragmentManager().findFragmentByTag(COMM_TAG);// Fragment lifeFragment = getSupportFragmentManager().findFragmentByTag(LIFE_TAG);//// getSupportFragmentManager().beginTransaction()//// getSupportFragmentManager().beginTransaction().hide(contactFragment)// .hide(commFragment).hide(lifeFragment).show(dialFragment).commit();////} else { getSupportFragmentManager().beginTransaction(). add(R.id.fl_content, FragmentFactory.createFragment(0), 'DialFragment'). add(R.id.fl_content, FragmentFactory.createFragment(1), 'CommFragment'). add(R.id.fl_content, FragmentFactory.createFragment(2), 'ContactFragment'). add(R.id.fl_content, FragmentFactory.createFragment(3), 'LifeFragment'). hide(FragmentFactory.createFragment(1)). hide(FragmentFactory.createFragment(2)). hide(FragmentFactory.createFragment(3)). show(FragmentFactory.createFragment(0)).commit();//}initClick(); }

嘗試過(guò)的解決辦法:1,為了解決多個(gè)fragment重疊顯示,在activity的中執(zhí)行了如下:

@Override protected void onSaveInstanceState(Bundle outState) {//super.onSaveInstanceState(outState); }

問(wèn)題現(xiàn)象:

android - 單activity+多fragment場(chǎng)景,應(yīng)用長(zhǎng)時(shí)間在后臺(tái)進(jìn)入前臺(tái)時(shí),fragment全部是空白

問(wèn)題解答

回答1:

@Override protected void onSaveInstanceState(Bundle outState) {//super.onSaveInstanceState(outState); }

這樣的解決辦法是不對(duì)的,這樣會(huì)導(dǎo)致從activity被銷毀是不能記住之前的顯示內(nèi)容,從而使界面空白、為了解決fragment重疊,你可以在注釋掉super.onSaveInstanceState(outState)的同時(shí),加上保存當(dāng)前fragment的代碼

@Overrideprotected void onSaveInstanceState(Bundle outState) { outState.putString(SPConst.SHOW_TAG, showFragmentTag);}

然后在回來(lái)的時(shí)候重新獲取之前的fragment,然后再顯示出來(lái)

@Overrideprotected void onRestoreInstanceState(Bundle savedInstanceState) { super.onRestoreInstanceState(savedInstanceState); if (savedInstanceState != null) {showFragmentTag = savedInstanceState.getString(SPConst.SHOW_TAG);if (showFragmentTag != null) { showFragment = fragmentManager.findFragmentByTag(showFragmentTag); switch (showFragmentTag) {case fragmentTag1: workFragment = showFragment; break;case fragmentTag2: patientFragment = showFragment; break;case fragmentTag3: synergyFragment = showFragment; break;case fragmentTag4: toolFragment = showFragment; break;case fragmentTag5: mineFragment = showFragment; break; }} }}回答2:

內(nèi)容有點(diǎn)亂,對(duì)于你這種需求,推薦使用FragmentTabHost,也就沒(méi)有這種亂七八糟的問(wèn)題了。

回答3:

直接用ViewPager就行

主站蜘蛛池模板: 91精品国产色综合久久 | 精品av久久久久电影 | 亚洲日韩视频 | 久久高清 | 亚洲97| 狠狠操电影 | 精品一二区| 欧美一区二区三区视频 | 国产精品色婷婷久久58 | 韩国av影院| 国产区在线 | 欧美日韩亚洲国产综合 | 少妇黄色 | 久久精品国产一区二区三区不卡 | 国产一区二区精品 | 国产高清免费视频 | 天天操天天射天天舔 | 亚洲欧洲成人在线 | 午夜爽爽爽男女免费观看 | 亚洲精品在线视频 | 91视频中文 | 中文字幕第十五页 | 久久av网站| 日韩欧美中文字幕在线视频 | 中文字幕av网站 | yeyeav| 在线观看www | 日日夜夜精品视频 | 亚洲精品中文字幕在线观看 | 精品国产精品三级精品av网址 | 国产伦精品一区二区三毛 | 久久久av| 狠狠操网站 | 中文字幕在线视频观看 | 国产第一亚洲 | 日韩一区二区视频 | 伊人网一区 | 久久免费精品视频 | 别c我啊嗯国产av一毛片 | 久久精品一区 | 91视频一88av |