后台进入前台弹密码

这个问题烦了了两天还是没有解决,最后在同事的帮助下解决了

问题:后台进入前台弹出密码界面,需要在Activity的生命周期resume()方法中实现,因为弹出了密码页面,原来要显示的又进入了后台,还会在重新调用onRestme()方法,所以:

public class BaseActivity extends AppCompatActivity {

    private static boolean isLeave = false; //记录是否应用进入后台
    /**
     * 每次进入后台再显示时要进入登录页面,而显示登录页面后之前要恢复的页面则又进入后台,故通过first
     * 来判断是否是从后台恢复显示
     */
    private boolean first=true;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        String theme = DBUtil.getSetting(this, DBUtil.APP_THEME);
        if (theme.length() > 0) {
            setTheme(Integer.parseInt(theme));
        } else {
            setTheme(R.style.AppTheme);
        }

        ActionBar actionBar = getSupportActionBar();
        if (actionBar != null) {
            actionBar.hide();
        }

        //因为大部分页面都是集成BaseActivity,故每个页面创建时都重新初始化一些变量
        isLeave=false;
        first=true;
    }

    @Override
    protected void onUserLeaveHint() {
        super.onUserLeaveHint();
        if(!isLeave && first){
            isLeave=true; //进入后台
        }
    }

    @Override
    protected void onResume() {
        super.onResume();
        first=true; //进入前台
        if(isLeave){
            first=false;
            Intent intent = new Intent(this, LoginActivity.class);
            intent.putExtra("type",0);
            startActivity(intent);
            isLeave=false;
        }
    }

    
}

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值