Last active
August 29, 2015 14:00
-
-
Save Trinea/4f3112d39b2268f34160 to your computer and use it in GitHub Desktop.
whether process of context is named with processName, can be used to avoid application onCreate multi times
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* whether this process is named with processName | |
* | |
* @param processName | |
* @return | |
*/ | |
private static boolean isNamedProcess(Context context, String processName) { | |
if (TextUtils.isEmpty(processName)) { | |
return true; | |
} | |
int pid = android.os.Process.myPid(); | |
ActivityManager manager = (ActivityManager)context.getSystemService(Context.ACTIVITY_SERVICE); | |
List<RunningAppProcessInfo> processInfoList = manager.getRunningAppProcesses(); | |
if (processInfoList == null) { | |
return true; | |
} | |
for (RunningAppProcessInfo processInfo : manager.getRunningAppProcesses()) { | |
if (processInfo.pid == pid && processName.equals(processInfo.processName)) { | |
return true; | |
} | |
} | |
return false; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment