Skip to content

Instantly share code, notes, and snippets.

@Trinea
Last active August 29, 2015 14:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Trinea/4f3112d39b2268f34160 to your computer and use it in GitHub Desktop.
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
/**
* 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