[英]Keep Activity on top
I would like to implement a screenLock activity, which triggers whenever the user locks the screen. 我想实现一个screenLock活动,该活动在用户锁定屏幕时触发。 I did this, but if the user opens the Application History I see two activities of my application: Sensitive-Activity and Lock-Activity. 我这样做了,但是如果用户打开“应用程序历史记录”,我会看到我的应用程序的两个活动:Sensitive-Activity和Lock-Activity。
If the user clicks on the Sensitive-Activity in the stack it comes foreground, without populating the Lock-Activity. 如果用户单击堆栈中的Sensitive-Activity,它将成为前台,而不填充Lock-Activity。 By doing this I have some serious security issues here. 通过这样做,我在这里遇到了一些严重的安全问题。
Could someone tell me how can I 'pin' Lock-Activity on the top, making it appear even user clicks on other activities? 有人可以告诉我如何将“锁定活动”固定在顶部,甚至在用户单击其他活动时也可以显示吗?
ps.: noHistroy on Sensitive-Activity is not a solution, since if no lock activated then users can't access to the app once it pushed to the background. ps.:Sensitive-Activity上的noHistroy不是解决方案,因为如果未激活锁,则用户将应用程序推送到后台后将无法访问该应用程序。
<activity
android:name=".Sensitive"
android:configChanges="keyboardHidden|orientation|screenSize" />
<activity
android:name=".Lock"
android:launchMode="singleInstance"
android:screenOrientation="portrait" />
In manifest file, remove, launcher tag from sensitive activity. 在清单文件中,从敏感活动中删除启动器标签。 After that only lock activity will show to user. 之后,仅锁定活动将显示给用户。 Current you may have set both activities as launcher activity, therefore you are watching two activities. 当前,您可能已将两个活动都设置为启动器活动,因此您正在观看两个活动。
By loading Sensitive activity from the background(history) run code to show Lock activity. 通过从后台(历史)运行代码加载敏感活动,以显示锁定活动。 You can register and implement Application lifecycle callbacks 您可以注册并实现应用程序生命周期回调
public class ForegroundWatchdog implements Application.ActivityLifecycleCallbacks {
@Override
public void onActivityCreated(Activity activity, Bundle bundle) {
}
@Override
public void onActivityStarted(Activity activity) {
}
@Override
public void onActivityResumed(Activity activity) {
}
@Override
public void onActivityPaused(final Activity activity) {
}
@Override
public void onActivityStopped(Activity activity) {
}
@Override
public void onActivitySaveInstanceState(Activity activity, Bundle bundle) {
}
@Override
public void onActivityDestroyed(Activity activity) {
}
}
To register callbacks: 要注册回调:
public class SomeActivity extends Activity {
Context appCtx = getApplicationContext();
if (appCtx instanceof Application) {
ForegroundWatchdod foregroundWatchdog = new ForegroundWatchdog();
Application application = (Application)appCtx;
application.registerActivityLifecycleCallbacks(foregroundWatchdog);
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.