android - isApplicationBroughtToBackground security feature misbehaves often -


i using implement security feature displays locking screen if app regains focus after coming different app.

now, problem security feature shown twice. after digging around bit noticed topactivity activitymanager.getrunningtasks(1) still activity returned from.

in case, offending lingering apps com.android.mms , com.google.android.apps.maps.

i have calling facility within application not misbehaving.

i baffled behavior.

this problematic case android. try following worked me:

have base class activities. in it:

@override protected void onpause() {     utils.wentinbackground(this);     super.onpause(); }  @override protected void onresume() {     utils.wentinforeground(this);     super.onresume(); } 

then in static utilities class have this:

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) {         // security lockdown here.     } }   public static boolean isapplicationsenttobackground(final context context) {     activitymanager = (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()) {              // security lockdown here again, if necessary.         }          // show security screen or whatever need to.     } }  public static boolean isloggedin() {     return loggedin; } 

Comments

Popular posts from this blog

python - Subclassed QStyledItemDelegate ignores Stylesheet -

java - HttpClient 3.1 Connection pooling vs HttpClient 4.3.2 -

SQL: Divide the sum of values in one table with the count of rows in another -