title: System services not available to activities before onCreate() on trying to implement getSystemService()
body: <p>So I'm trying to implement a AlertDialog which should open up on pressing the the 'activate' button, but  on pressing the button, the app crashes.</p>
  
  <p>Here's my code.</p>
  
  <p>MainActivity-</p>
  
  <pre><code>public class MainActivity extends Activity {
  
  Button activateButton;
  
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
  
      activateButton = (Button)findViewById(R.id.activate);
      activateButton.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View view) {
              Speed s = new Speed();
          }
      });
  
  }
  </code></pre>
  
  <p>And here's another class called Speed which contains the code for AlertDialog</p>
  
  <pre><code>public class Speed extends Activity {
      LocationManager mManager;
      final LocationManager manager = (LocationManager) getSystemService(Context.LOCATION_SERVICE );
      AlertDialog.Builder box = new AlertDialog.Builder(this);
      Speed(){
          Status();
      }
  
      private void Status(){
  
          if(!mManager.isProviderEnabled(LocationManager.GPS_PROVIDER)){
              DialogBox();
          }
      }
  
      protected void DialogBox(){
          AlertDialog.Builder box = new AlertDialog.Builder(this);
          box.setTitle("The GPS needs to be enabled. Would you like to enable the GPS?").setCancelable(false)
                  .setPositiveButton("Yes", new DialogInterface.OnClickListener(){
                      public void onClick(DialogInterface dialog, int id){
                          startActivity(new Intent(android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS));
                      }
                  }).setNegativeButton("No", new DialogInterface.OnClickListener(){
              public void onClick(DialogInterface dialog, int id){
                  dialog.cancel();
              }
          });
          final AlertDialog alert = box.create();
          alert.show();
  
      }
  
  }
  </code></pre>
  
  <p>Also, here's the log with error in the context </p>
  
  <pre><code>10-01 21:27:00.439: E/AndroidRuntime(5503): FATAL EXCEPTION: main
  10-01 21:27:00.439: E/AndroidRuntime(5503): java.lang.IllegalStateException: System services not available to Activities before onCreate()
  10-01 21:27:00.439: E/AndroidRuntime(5503):     at android.app.Activity.getSystemService(Activity.java:3989)
  10-01 21:27:00.439: E/AndroidRuntime(5503):     at com.scimet.admin.driveon.Speed.&lt;init&gt;(Speed.java:12)
  10-01 21:27:00.439: E/AndroidRuntime(5503):     at com.scimet.admin.driveon.MainActivity$1.onClick(MainActivity.java:25)
  10-01 21:27:00.439: E/AndroidRuntime(5503):     at android.view.View.performClick(View.java:3534)
  10-01 21:27:00.439: E/AndroidRuntime(5503):     at android.view.View$PerformClick.run(View.java:14263)
  10-01 21:27:00.439: E/AndroidRuntime(5503):     at android.os.Handler.handleCallback(Handler.java:605)
  10-01 21:27:00.439: E/AndroidRuntime(5503):     at android.os.Handler.dispatchMessage(Handler.java:92)
  10-01 21:27:00.439: E/AndroidRuntime(5503):     at android.os.Looper.loop(Looper.java:137)
  10-01 21:27:00.439: E/AndroidRuntime(5503):     at android.app.ActivityThread.main(ActivityThread.java:4441)
  10-01 21:27:00.439: E/AndroidRuntime(5503):     at java.lang.reflect.Method.invokeNative(Native Method)
  10-01 21:27:00.439: E/AndroidRuntime(5503):     at java.lang.reflect.Method.invoke(Method.java:511)
  10-01 21:27:00.439: E/AndroidRuntime(5503):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
  10-01 21:27:00.439: E/AndroidRuntime(5503):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
  10-01 21:27:00.439: E/AndroidRuntime(5503):     at dalvik.system.NativeStart.main(Native Method)
  </code></pre>
  
  <p>This is my first Android project. and on searching for multiple hours to try and resolve this issue, I've ended up with no solution. Please point out the mistake.</p>
  
  <p>Thank you!</p>