现在,问题是安全功能有时会显示两次.在挖掘了一下后,我注意到ActivityManager.getRunningTasks(1)中的topActivity有时仍然是您刚刚返回的活动.
就我而言,令人讨厌的挥之不去的应用程序是com.android.mms和com.Google.androID.apps.maps.
我在应用程序中也有一个呼叫设施,但它没有行为不端.
我对这种行为感到困惑.
解决方法 这对 Android来说确实是个问题.尝试下面对我有用的:为您的活动准备基础课程.在里面:
@OverrIDeprotected voID onPause() { Utils.wentInBackground(this); super.onPause();}@OverrIDeprotected voID onResume() { Utils.wentInForeground(this); super.onResume();}
然后在静态实用程序类中有这样的:
public static voID wentInBackground(final Activity which) { inBackground = true; lastPaused = which.getClass().getSimplename(); final PowerManager powerManager = (PowerManager) which.getSystemService(POWER_SERVICE); final boolean isScreenOn = powerManager.isScreenOn(); if (isApplicationSentToBackground(which) || !isScreenOn) { // Do your security lockdown here. }}public static boolean isApplicationSentToBackground(final Context context) { ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); List<RunningTaskInfo> tasks = am.getRunningTasks(1); if (!tasks.isEmpty()) { Componentname topActivity = tasks.get(0).topActivity; if (!topActivity.getPackagename().equals(context.getPackagename())) { return true; } } return false;}public static voID wentInForeground(final Activity which) { inBackground = false; final String activityname = which.getClass().getSimplename(); if (lastPaused.equals(activityname) || !isLoggedIn()) { if (isLoggedIn()) { // Do your security lockdown here again,if necessary. } // Show your security screen or whatever you need to. }}public static boolean isLoggedIn() { return loggedIn;}总结
以上是内存溢出为你收集整理的android – isApplicationBroughtToBackground安全功能经常行为不端全部内容,希望文章能够帮你解决android – isApplicationBroughtToBackground安全功能经常行为不端所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)