亚洲精品久久久中文字幕-亚洲精品久久片久久-亚洲精品久久青草-亚洲精品久久婷婷爱久久婷婷-亚洲精品久久午夜香蕉

您的位置:首頁技術文章
文章詳情頁

android - 單activity+多fragment場景,應用長時間在后臺進入前臺時,fragment全部是空白

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

問題描述

1,問題: 應用長期在后臺的場景下,進入前臺時,fragment顯示為空白2,app框架大體實現: 1個activity+多個Fragment,使用的是add()方法以及 hide(),show()方法,顯示fragment3,相關代碼:

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,個推 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);//第一次登錄系統時,修改數據庫的Istravelrely字段if (!SpUtils.getSynDB(getApplicationContext())) { ThreadPoolUtil.getmExecutor().execute(new Runnable() {@Overridepublic void run() { CopyLocalContactsUtils.checkIsTravelRely(getApplication()); SpUtils.setSynDB(getApplicationContext());} });}//初始化mBottomDial為選中狀態,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(); }

嘗試過的解決辦法:1,為了解決多個fragment重疊顯示,在activity的中執行了如下:

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

問題現象:

android - 單activity+多fragment場景,應用長時間在后臺進入前臺時,fragment全部是空白

問題解答

回答1:

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

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

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

然后在回來的時候重新獲取之前的fragment,然后再顯示出來

@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:

內容有點亂,對于你這種需求,推薦使用FragmentTabHost,也就沒有這種亂七八糟的問題了。

回答3:

直接用ViewPager就行

主站蜘蛛池模板: 羞羞色院91精品网站 | 91福利免费体验区观看区 | 伊人成伊人成综合网2222 | 国产原创在线观看 | 350gao免费永久视频 | 国产精品自拍一区 | 玖玖在线国产精品 | 在线国产一区二区 | 51视频在线观看免费国产 | 日本免费va毛片在线看大 | 日本精品久久久久中文字幕 1 | 亚洲综合一区二区不卡 | 性精品 | 国产成人精品亚洲午夜麻豆 | 美国特级片 | 亚州一级片 | 亚洲精品视频一区 | 91在线观 | 久久久久国产午夜 | 综合久久一区二区三区 | 国产日韩精品欧美一区视频 | 高颜值露脸极品在线播放 | 中文字幕美日韩在线高清 | 免费国产黄色片 | 性亚洲精品 | 高清成人综合 | 国内成人免费视频 | 亚洲精品午夜级久久久久 | 国产精品页| 日韩欧美国产精品第一页不卡 | 亚洲精品国产摄像头 | a级毛片视频免费观看 | 成人超污免费网站在线看 | 成人爱av18丰满| 日韩欧美视频在线播放 | 欧美精品一区二区三区视频 | 亚洲色图在线观看视频 | 国产精品探花千人斩久久 | 亚洲欧美一区二区三区麻豆 | 日本护士xxxx黑人巨大 | 国产a级特黄的片子视频免费 |