PackageManager in Android giving duplicates -
i might novice programmer packagemanager complicated ! going show makes no sense:
i able pull out names of applications on device if try save array can save half of them.
packagemanager packagemanager = null; list<applicationinfo> appslisttest = new arraylist<applicationinfo>(); packagemanager = context.getpackagemanager(); appslisttest = packagemanager.getinstalledapplications(0); log.d("log", " new pm : " + appslisttest.size()); iterator<applicationinfo> iterator = appslisttest.iterator(); int counter = 0; string[] appname = new string[appslisttest.size()]; while (iterator.hasnext()) { log.d("log", string.valueof(counter)); // when print out see 64 apps. great log.d("log", (string) iterator.next().loadlabel(packagemanager)); // when try save array 30 appname[counter] = (string) iterator.next().loadlabel(packagemanager); counter++; }
it makes no sense !!!
so if comment out appname array print log.d out 61 times. when include array log out 31 times.
and value initialise appname 64:
log.d("log", " new pm : " + appslisttest.size());
application not crash or anything.
can show me code on how app name, uid , icon ?
iterator.next()
advances list - advancing twice per loop. instead, should save result iterator.next()
variable , use within loop:
while (iterator.hasnext()) { log.d("log", string.valueof(counter)); // call iterator.next() once per loop applicationinfo info = iterator.next(); string label = (string) info.loadlabel(packagemanager); log.d("log", label); appname[counter] = label; counter++; }
Comments
Post a Comment