android fragment 白屏,Android,fragment_单activity+多fragment场景,应用长时间在后台进入前台时,fragment全部是空白,Android,fragm...

单activity+多fragment场景,应用长时间在后台进入前台时,fragment全部是空白

1,问题:

应用长期在后台的场景下,进入前台时,fragment显示为空白

2,app框架大体实现:

1个activity+多个Fragment,使用的是add()方法以及 hide(),show()方法,显示fragment

3,相关代码:

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() {

@Override

public 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() {

@Override

public void run() {

CopyLocalContactsUtils.checkIsTravelRely(getApplication());

SpUtils.setSynDB(getApplicationContext());

}

});

}

//初始化mBottomDial为选中状态,fl_content填充DialFragment

mBottomDial.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);

}

问题现象:

相关阅读:

在react的componentDidMount中触发input框的focus无效是为什么?

js怎么实现将流写成文件实现pdf在线预览(文件在数据库里)

MySQL 分表有什么坏处和改进意见?

在yii2的GridView中将某字段id转换为名称每条语句循环2次的问题?

segmentfault的问答详情页面是如何实现与android原生交互的?

为什么Linux使用正则grep [a-z] /etc/passwd -n会把带t的行给显示出来?

远程桌面连接windows服务器的时候,连接可以起一个名字吗?好几个人连接的时候容易搞混了?

怎么使用js将json文件转成csv文件

如何在Golang中获取系统当前活动窗体的标题文本?

新手请教一个关于class的问题

做一个视频播放器,想实现一个功能,如果3秒不点击屏幕任何,则下方一个界面布局(显示按钮那些的)自动消失。

iOS中的webview加载的是html。。那么html中的外联js和CSS文件怎么加载?

Java为什么不能同时

定义数组的长度和初始值

iOS中如何获取我们想要知道的控件的key值?

如何在docker容器中运行一个jar而不会被退出?

Xcode新建iOS Cocoa Touch Class和新建Header File与Objective-C File有区别吗?

jQuery 这两行能写一起吗?

webpack开启inline后,修改代码,能热加载,但是一直报这个错,点击继续后,页面又能正常刷新

AFNetworking异步post请求

phalcon 访问IndexController 中只能访问indexAction方法,访问不了testAction

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值