Code:/**
* 需要权限:android.permission.GET_TASKS
*
* @param context
* @return
*/
public boolean isApplicationBroughtToBackground(Context context)
{
ActivityManager am = (ActivityManager) context
.getSystemService(Context.ACTIVITY_SERVICE);
List<RunningTaskInfo> tasks = am.getRunningTasks(1);
if (tasks != null && !tasks.isEmpty())
{
ComponentName topActivity = tasks.get(0).topActivity;
Debug.i(TAG, "topActivity:" + topActivity.flattenToString());
Debug.f(TAG, "topActivity:" + topActivity.flattenToString());
if(!topActivity.getPackageName().
equals(context.getPackageName()))
{
return true;
}
}
return false;
}
链接:http://www.jb51.net/article/67656.htm