title: IllegalStateException: System services not available to Activities before onCreate()
body: <p>I keep getting a Fatal java.lang.IllegalStateException error when I start up my app and I'm not sure why.  Basically all I'm trying to do is return the running processes and tasks every 10 seconds.</p>
  
  <p>Here's my code:</p>
  
  <pre><code>public class MainActivity extends Activity {
  
      Handler h = new Handler();
      public static final String TAG = "MyActivity";
      int s;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
          Checker();
      }
  
      public void Checker() {
          Handler h = new Handler();
          h.post(check);
      }
  
      Runnable check = new Runnable() {
          ActivityManager am = (ActivityManager) getSystemService(ACTIVITY_SERVICE);
          public void run() {
              Processes(am);
              Tasks(am);
              h.postAtTime(check, 10000);
          }
      };
  
      public void Processes(ActivityManager am) {
          List&lt;ActivityManager.RunningAppProcessInfo&gt; l = am.getRunningAppProcesses();
          s = l.size();
          for(int i = 0; i &lt; s; i++) {
              Log.d(TAG, "Process:  " + l.get(i).processName);
          }
      }
  
      public void Tasks(ActivityManager am) {
          List&lt;ActivityManager.RunningTaskInfo&gt; l = am.getRunningTasks(1000);
          s = l.size();
          for(int i = 0; i &lt; s; i++) {
              // .baseActivity returns the process that started the Task
              Log.d(TAG, "Task:  " + l.get(i).baseActivity.getPackageName());
          }
      }
  
      @Override
      public boolean onCreateOptionsMenu(Menu menu) {
          // Inflate the menu; this adds items to the action bar if it is present.
          getMenuInflater().inflate(R.menu.activity_main, menu);
          return true;
      }
  }
  </code></pre>
  
  <p>And here are my logs:</p>
  
  <pre><code>12-18 08:03:53.190: E/AndroidRuntime(1577): FATAL EXCEPTION: main
  12-18 08:03:53.190: E/AndroidRuntime(1577): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.androidside/com.example.androidside.MainActivity}: java.lang.IllegalStateException: System services not available to Activities before onCreate()
  12-18 08:03:53.190: E/AndroidRuntime(1577):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2106)
  12-18 08:03:53.190: E/AndroidRuntime(1577):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
  12-18 08:03:53.190: E/AndroidRuntime(1577):     at android.app.ActivityThread.access$600(ActivityThread.java:141)
  12-18 08:03:53.190: E/AndroidRuntime(1577):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
  12-18 08:03:53.190: E/AndroidRuntime(1577):     at android.os.Handler.dispatchMessage(Handler.java:99)
  12-18 08:03:53.190: E/AndroidRuntime(1577):     at android.os.Looper.loop(Looper.java:137)
  12-18 08:03:53.190: E/AndroidRuntime(1577):     at android.app.ActivityThread.main(ActivityThread.java:5039)
  12-18 08:03:53.190: E/AndroidRuntime(1577):     at java.lang.reflect.Method.invokeNative(Native Method)
  12-18 08:03:53.190: E/AndroidRuntime(1577):     at java.lang.reflect.Method.invoke(Method.java:511)
  12-18 08:03:53.190: E/AndroidRuntime(1577):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
  12-18 08:03:53.190: E/AndroidRuntime(1577):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
  12-18 08:03:53.190: E/AndroidRuntime(1577):     at dalvik.system.NativeStart.main(Native Method)
  12-18 08:03:53.190: E/AndroidRuntime(1577): Caused by: java.lang.IllegalStateException: System services not available to Activities before onCreate()
  12-18 08:03:53.190: E/AndroidRuntime(1577):     at android.app.Activity.getSystemService(Activity.java:4463)
  12-18 08:03:53.190: E/AndroidRuntime(1577):     at com.example.androidside.MainActivity$1.&lt;init&gt;(MainActivity.java:54)
  12-18 08:03:53.190: E/AndroidRuntime(1577):     at com.example.androidside.MainActivity.&lt;init&gt;(MainActivity.java:53)
  12-18 08:03:53.190: E/AndroidRuntime(1577):     at java.lang.Class.newInstanceImpl(Native Method)
  12-18 08:03:53.190: E/AndroidRuntime(1577):     at java.lang.Class.newInstance(Class.java:1319)
  12-18 08:03:53.190: E/AndroidRuntime(1577):     at android.app.Instrumentation.newActivity(Instrumentation.java:1054)
  12-18 08:03:53.190: E/AndroidRuntime(1577):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2097)
  12-18 08:03:53.190: E/AndroidRuntime(1577):     ... 11 more
  </code></pre>
  
  <p>Thanks for the help.</p>