title: Android Application vs Activity
body: <p>I have written a few Android apps, and have always declared a starting <code>Activity</code> as the:</p>
  
  <pre><code>&lt;intent-filter&gt;
      &lt;action android:name="android.intent.action.MAIN" /&gt;
  &lt;category android:name="android.intent.category.LAUNCHER" /&gt;
  &lt;/intent-filter&gt;
  </code></pre>
  
  <p>It would be great for scoping some global methods, statics, shared prefs, etc if I could start my app using an <code>Application</code> that then calls the first <code>Activity</code> from it's <code>onCreate()</code> after setting up prefs, etc, but I haven't been able to find any examples of this design pattern... when I try this in code, I get a <code>ClassCastException</code>:</p>
  
  <pre><code>public class MyApplication extends Application {
  @Override
      public void onCreate() {
          super.onCreate();
  
          // do stuff (prefs, etc)
  
          // start the initial Activity
          Intent i = new Intent(this, InitialActivity.class);
      startActivity(i);
      }
  }
  </code></pre>
  
  <p><code>InitialActivity.class</code> is indeed an <code>Activity</code> that works fine if I set it to be <code>MAIN</code>, but trying to start it from <code>MyApplication</code> that is declared <code>MAIN</code> generates the error. Probably a very silly question, but am I tackling this all wrong?</p>
  
  <p>Thanks,</p>
  
  <p>Paul</p>