0
public void CheckProcesses()
{
    ActivityManager activityManager = (ActivityManager)BaseContext.GetSystemService(Context.ActivityService);
    ActivityManager.MemoryInfo memoryInfo = new ActivityManager.MemoryInfo();
    activityManager.GetMemoryInfo(memoryInfo);

    List<ActivityManager.RunningAppProcessInfo> runningAppProcesses = activityManager.RunningAppProcesses as List<ActivityManager.RunningAppProcessInfo>;
    //List<ActivityManager.RunningTaskInfo> appProcessInfos = GetActiveProcesses();
    //List<string> pids = new List<string>();
    try
    {
        foreach (ActivityManager.RunningAppProcessInfo item in runningAppProcesses) // <- here is the exception
        {
            //pids.Add(item.Pid.ToString());
        }
    }
    catch(Exception ex) { Android.Widget.Toast.MakeText(this, ex.ToString(), Android.Widget.ToastLength.Long).Show(); }
    finally
    {
        Toast.MakeText(this, runningAppProcesses.Capacity.ToString(), Android.Widget.ToastLength.Long).Show(); // <- Here also
    }
}

Have been trying to make an android task manager with Xamarin.Android. Have been following this answer: Xamarin Android: Get ALL processes located in memory

Throws System.NullReferenceException: 'Object reference not set to an instance of an object.'

P.S I have tried all the permissions what are available..

Selim Yildiz
  • 4,224
  • 6
  • 14
  • 25
Dude4
  • 83
  • 1
  • 8
  • 3
    Does this answer your question? [What is a NullReferenceException, and how do I fix it?](https://stackoverflow.com/questions/4660142/what-is-a-nullreferenceexception-and-how-do-i-fix-it). Also you could do a check before *trying* to iterate an object: `if(runningAppProcesses != null){foreach (ActivityManager.RunningAppProcessInfo item in runningAppProcesses)}`. Also, if you set a breakpoint on `activityManager.RunningAppProcesses` does that return anything? – zaggler Feb 14 '20 at 13:18
  • It seems like getting app processes does not work in xamarin – Dude4 Feb 14 '20 at 18:57

0 Answers0