Android Application's onCreate called mutiple times, How to guarantee only run initialize res one time -
i going run initialize code app, there 2 process, 1 main process, keep active process. application oncreate() run 2 times, want run 1 time initialize code in main process. know there way, can activitymanager running process information , comparing pid know current process information, below code:
public static string getprocessnamebypid(context context, int pid){ activitymanager manager = (activitymanager) context.getsystemservice(context.activity_service); for(activitymanager.runningappprocessinfo processinfo : manager.getrunningappprocesses()){ if(processinfo.pid == pid){ return processinfo.processname; } } return ""; }
but android 5.0+ killed getrunningtasks(int) , getrunningappprocesses(), there other ideas?
i check if global variable declared.
private string globalstring; private int globalint; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); if (globalstring == nil) { globalstring = "declaration"; globalint = 42; //everything else } }
Comments
Post a Comment