title: Custom global Application class breaks with "android.app.Application cannot be cast to"
body: <p>I have a custom global class which looks like this</p>
  
  <pre><code>import android.app.Application;
  
  public class MyApp extends Application {
  
      public String MainAct;
  
      public String getMainAct() {
          return MainAct;
      }
  
      public void setMainAct(String mainAct) {
          MainAct = mainAct;
      }
  }
  </code></pre>
  
  <p>I want to preserve a string in this class via another <code>Activity</code> in its <code>onCreate</code> method. </p>
  
  <pre><code>    String local = "myLocalVariable";
      ((MyApp) getApplication()).setMainAct(local); //breaks here!!!
      String name = ((MyApp) getApplication()).getMainAct();
  </code></pre>
  
  <p>It breaks on the marked line with error: <code>Caused by: java.lang.ClassCastException: android.app.Application cannot be cast to com.xxx.yyy.global.MyApp</code></p>
  
  <p>I've checked the code for five times and I cannot find error anywhere. Can anyone tell me where the error is?!</p>
  
  <p>Thanks</p>