我怎样才能知道我的应用是从后台重新开始? [英] How can I tell if my Application is resumed from background?

查看:136
本文介绍了我怎样才能知道我的应用是从后台重新开始?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要当它在后台锁定我的应用程序, 它恢复时,我想显示自己的锁屏。锁屏是我的应用程序的活动。

I want to lock my application when it goes in background and when it resumes I want to display my own lock screen. The lock screen is an Activity of my application.

在成功entring密码的用户可以看到恢复活动 否则他不能。

After successfully entring password the user can see the resumed Activity else he can't.

我怎样才能做到这一点?

How can I do this?

推荐答案

可以实现,如果你有一个全球性的活动MyActivity,所有的活动,从它延伸。

You can achieve that if you have a global Activity "MyActivity" and all the activities extend from it.

然后你覆盖的onPause和MyActivity

Then you override onPause and onStop methods on "MyActivity"

@Override
public void onPause()
{
    super.onPause();
    setLockStatus(false);
}

@Override
public void onStop()
{
    super.onStop();
    setLockStatus(true);
}

@Override
public void onResume()
{
    super.onResume();
    checkLockScreen();
}

编辑:显然,你需要创建方法setLockStatus和checkLockScreen,做任何你想要的(如保存在共享preferences状态)

Obviously you need to create the methods setLockStatus and checkLockScreen and do whatever you want (like save the status on sharedPreferences).

这篇关于我怎样才能知道我的应用是从后台重新开始?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆