NativeScript / docs-v8

https://docs.nativescript.org
29 stars 42 forks source link

Example in docs does not recognize "android.app.Application" #79

Closed mannueru closed 2 years ago

mannueru commented 2 years ago

I'm starting with nativescript 8 but the documentation for version 8 is horrible, version 7 has much better documentation but they are not compatible in most cases.

The official documentation shows an example to extending the android application, but it does not show its imports:

@NativeClass()
@JavaProxy('org.myApp.Application')
class Application extends android.app.Application {
  public onCreate(): void {
    super.onCreate()
    // At this point modules have already been initialized
    // Enter custom initialization code here
  }

  public attachBaseContext(baseContext: android.content.Context) {
    super.attachBaseContext(baseContext)
    // This code enables MultiDex support for the application (if needed)
    // androidx.multidex.MultiDex.install(this);
  }
}

I couldn't get the "android.app.Application" class to be recognized, even after importing the following:

import { android } from '@nativescript/core/application';

Looking at the content of "@nativescript/core/application", I see that those properties do not exist and that for example the property "android.app.Application" was changed to "nativeApp".

I don't know if I'm importing the correct class or maybe I'm missing a type import or something like that, because in the NativeScript source codes they refer to "android.app.Application" without any import that refers to it.

I know I'm missing something, but seriously the official documentation for version 8 needs to be corrected or improved

rigor789 commented 2 years ago

android.app.Application is the android native API https://developer.android.com/reference/android/app/Application

It doesn't need to be imported - it's defined during runtime.

If you are getting type errors, you likely need to install @nativescript/types to include the native android api types - but you can also just //@ts-ignore the line.

mannueru commented 2 years ago

thanks!!! I already understood the process