title: How to extend application class in xamarin android
body: <p>I want to extend the Android application and I want to override oncreate method.
  But for some reason its been very terrible...Only if I remove [Application] I am able to run it but according to this <a href="https://forums.xamarin.com/discussion/2147/what-is-the-recipe-to-have-a-working-application-derived-class" rel="noreferrer">link</a> we have to add [Application]</p>
  
  <pre><code>[Application]
  public class MainApp : Application
  {
  public MainApp(IntPtr javaReference, JniHandleOwnership transfer) : base(javaReference, transfer)
  {
  }
  
  public override void OnCreate()
  {
      base.OnCreate();
      //app init ...
  }
  }
  </code></pre>
  
  <p>Can anybody clarify me what is the rightway to extend application class in xamarin android</p>
  
  <p><strong>Update</strong></p>
  
  <p>If I don't remove [application] I am exactly getting the below error</p>
  
  <blockquote>
    <p>/Library/Frameworks/Mono.framework/External/xbuild/Xamarin/Android/Xamarin.Android.Common.targets:
    Error: Error executing task GenerateJavaStubs: Application cannot have
    both a type with an [Application] attribute and an
    [assembly:Application] attribute. (myapp.Droid)</p>
  </blockquote>
  
  <p>If I application then it compiles but it throws following runtime error</p>
  
  <blockquote>
    <p>[AndroidRuntime] Shutting down VM [AndroidRuntime] FATAL EXCEPTION:
    main [AndroidRuntime] Process: com.test.myapp, PID: 6524
    [AndroidRuntime] java.lang.RuntimeException: Unable to instantiate
    application com.test.myapp.MainApp: java.lang.ClassNotFoundException:
    Didn't find class "com.test.myapp.MainApp" on path: DexPathList[[zip
    file
    "/data/app/com.test.myapp-1/base.apk"],nativeLibraryDirectories=[/data/app/com.test.myapp-1/lib/arm,
    /data/app/com.test.myapp-1/base.apk!/lib/armeabi-v7a, /system/lib,
    /vendor/lib]] [AndroidRuntime]    at
    android.app.LoadedApk.makeApplication(LoadedApk.java:802)
    [AndroidRuntime]  at
    android.app.ActivityThread.handleBindApplication(ActivityThread.java:5377)
    [AndroidRuntime]  at
    android.app.ActivityThread.-wrap2(ActivityThread.java)
    [AndroidRuntime]  at
    android.app.ActivityThread$H.handleMessage(ActivityThread.java:1545)
    [AndroidRuntime]  at
    android.os.Handler.dispatchMessage(Handler.java:102) [AndroidRuntime]
      at android.os.Looper.loop(Looper.java:154) [AndroidRuntime]     at
    android.app.ActivityThread.main(ActivityThread.java:6119)
    [AndroidRuntime]  at java.lang.reflect.Method.invoke(Native Method)
    [AndroidRuntime]  at
    com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
    [AndroidRuntime]  at
    com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
    [AndroidRuntime] Caused by: java.lang.ClassNotFoundException: Didn't
    find class "com.test.myapp.MainApp" on path: DexPathList[[zip file
    "/data/app/com.test.myapp-1/base.apk"],nativeLibraryDirectories=[/data/app/com.test.myapp-1/lib/arm,
    /data/app/com.test.myapp-1/base.apk!/lib/armeabi-v7a, /system/lib,
    /vendor/lib]] [AndroidRuntime]    at
    dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
    [AndroidRuntime]  at
    java.lang.ClassLoader.loadClass(ClassLoader.java:380) [AndroidRuntime]
      at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
    [AndroidRuntime]  at
    android.app.Instrumentation.newApplication(Instrumentation.java:992)
    [AndroidRuntime]  at
    android.app.LoadedApk.makeApplication(LoadedApk.java:796)
    [AndroidRuntime]  ... 9 more</p>
  </blockquote>
  
  <p>Here is my manifest <a href="http://text-share.com/view/9d9107d6" rel="noreferrer">file</a></p>