displaying the list of currently running task's packages and classes in my android application -
here scenario want display list of running task's packages , classes in android application,i have written code giving me run time error..can me solve this.. below code....is idea correct or don't mind if code program..
activitymanager actm = null; list< activitymanager.runningtaskinfo> runningtasks= actm.getrunningtasks(5); for(i=0;i<5;i++) { componentname comname=runningtasks.get(i).topactivity; string packname = comname.getpackagename(); string classname = comname.getclassname(); toast toast1 = toast.maketext(context, packname, duration); toast1.show(); }
for 1 thing, need initialize actm getting activity manager instance:
activitymanager actm = (activitymanager) getsystemservice(activity_service); for another, seem not have protection against possibility 1 of these functions may return null object - have verify hasn't before try call method of object in question. example, if there less 5 running tasks?
(incidentally, information returned not considered reliable - it's more of curiosity api 1 can depend on)
Comments
Post a Comment