I have :-
Class Abc extends Activity(){
private ActivityManager am;
private List<RunningAppProcessInfo> rList;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
@Override
public void onStart (Bundle savedInstanceState) {
super.onStart(savedInstanceState);
}
@Override
public boolean onTouchEvent(MotionEvent event) {
super.onTouchEvent(event);
rList= am.getRunningAppProcesses();
Log.e("MAIN", rList.isEmpty() +" .");
return true;
}
}
am.getRunningAppProcesses()
is always null
even though i have foreground apps running, the active applications also shows them correctly. i know that its supposed to return null
if there's nothing else running, but i launch other apps (gmail, camera, for testing)
Is this a permissions issue?
figured it out.
For ActivityManager am
, since the constructor is private
, and no static
instances are available, it must be instantiated like:
am = (ActivityManager)getSystemService(ACTIVITY_SERVICE);
Hope this is useful to someone stuck with a similar problem
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.