4

My app contain lock screen which will be come up when app brought from background.

I am facing a problem particularly onwards kitkat 4.4.

While app goes in background, i am checking that the Is application going in background? in onPause() method of activity which was on foreground by following code.

private boolean isApplicationBroughtToBackground() 
{ 
    ActivityManager am = (ActivityManager)getSystemService(Context.ACTIVITY_SERVICE); 
    List<RunningTaskInfo> tasks = am.getRunningTasks(1); 
    if (!tasks.isEmpty()) { 
        ComponentName topActivity = tasks.get(0).topActivity; 
        if (!topActivity.getPackageName().equals(getPackageName())) { 
            return true; 
        } 
    } 

    return false; 
}

I am calling above method in onPause() and on basis of returning value i am taking decision to show lock screen.

As per my observation this method is returning true in below 4.4 OS, but its returned false onword 4.4.

If i make a call in onStop() method i am getting true in all the cases.

I want to know whats the changes made in kitkat in context of activity life cycle?

Need to know reason why its behaving differently in kitkat?

Rohan Patel
  • 1,758
  • 2
  • 21
  • 38
  • 1
    Maybe you'll like to check out this link https://stackoverflow.com/questions/19910381/check-if-app-is-in-background – matthew5025 Aug 19 '14 at 06:02

0 Answers0