{"action":"created","issue":{"url":"https://api.github.com/repos/NativeScript/android-runtime/issues/462","repository_url":"https://api.github.com/repos/NativeScript/android-runtime","labels_url":"https://api.github.com/repos/NativeScript/android-runtime/issues/462/labels{/name}","comments_url":"https://api.github.com/repos/NativeScript/android-runtime/issues/462/comments","events_url":"https://api.github.com/repos/NativeScript/android-runtime/issues/462/events","html_url":"https://github.com/NativeScript/android-runtime/issues/462","id":156672663,"number":462,"title":"Errors extending NativeScriptActivity on Android","user":{"login":"enchev","id":5804953,"avatar_url":"https://avatars.githubusercontent.com/u/5804953?v=3","gravatar_id":"","url":"https://api.github.com/users/enchev","html_url":"https://github.com/enchev","followers_url":"https://api.github.com/users/enchev/followers","following_url":"https://api.github.com/users/enchev/following{/other_user}","gists_url":"https://api.github.com/users/enchev/gists{/gist_id}","starred_url":"https://api.github.com/users/enchev/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/enchev/subscriptions","organizations_url":"https://api.github.com/users/enchev/orgs","repos_url":"https://api.github.com/users/enchev/repos","events_url":"https://api.github.com/users/enchev/events{/privacy}","received_events_url":"https://api.github.com/users/enchev/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2016-05-25T06:27:20Z","updated_at":"2016-05-25T06:27:21Z","closed_at":null,"body":"_From @chimon2000 on May 23, 2016 22:30_\n\n## Versions\r\ntns: 2.0.1\r\ntns-core-modules: 2.0.1\r\ntns-android: 2.0.0\r\n\r\n## Description\r\nWhen attempting to extend NativeScriptActivity, I run into several issues:\r\n\r\n````\r\nvar app = require(\"application\");\r\nvar mainActivity = com.tns.NativeScriptActivity.extend({\r\n    onCreate: function (savedState) {\r\n        console.log('loaded');\r\n        // call the base NativeScriptActivity.onCreate method\r\n        // the \"this\" variable points to a NativeScriptActivity instance\r\n        this.super.onCreate(savedState);\r\n\r\n        // create a button and set it as the main content\r\n        var button = new android.widget.Button(this);\r\n        button.setText(\"Hello World\");\r\n\r\n        this.setContentView(button);\r\n    }\r\n});\r\n\r\nvar applicationInitObject = {\r\n    getActivity: function (intent) {\r\n        // this method is called whenever a new instance of NativeScriptActivity is about to be created\r\n        return mainActivity;\r\n    },\r\n    onCreate: function () {\r\n        // This is the first method called. Called from the android.app.Application.onCreate method.\r\n    }\r\n}\r\n\r\napp.init(applicationInitObject);\r\n````\r\nI took the example from [here](https://docs.nativescript.org/runtimes/android/getting-started/hello-world), and I assume that the information is stale since it refers to bootstrap.js. Unfortunately, I can't find anymore documentation around the feature.\n\n_Copied from original issue: NativeScript/NativeScript#2166_"},"comment":{"url":"https://api.github.com/repos/NativeScript/android-runtime/issues/comments/221484478","html_url":"https://github.com/NativeScript/android-runtime/issues/462#issuecomment-221484478","issue_url":"https://api.github.com/repos/NativeScript/android-runtime/issues/462","id":221484478,"user":{"login":"enchev","id":5804953,"avatar_url":"https://avatars.githubusercontent.com/u/5804953?v=3","gravatar_id":"","url":"https://api.github.com/users/enchev","html_url":"https://github.com/enchev","followers_url":"https://api.github.com/users/enchev/followers","following_url":"https://api.github.com/users/enchev/following{/other_user}","gists_url":"https://api.github.com/users/enchev/gists{/gist_id}","starred_url":"https://api.github.com/users/enchev/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/enchev/subscriptions","organizations_url":"https://api.github.com/users/enchev/orgs","repos_url":"https://api.github.com/users/enchev/repos","events_url":"https://api.github.com/users/enchev/events{/privacy}","received_events_url":"https://api.github.com/users/enchev/received_events","type":"User","site_admin":false},"created_at":"2016-05-25T06:27:21Z","updated_at":"2016-05-25T06:27:21Z","body":"_From @chimon2000 on May 24, 2016 17:17_\n\n## Further Details\r\n\r\nWhat I am actually trying to do is extend the NativeScriptActivity to add an event for user interaction that I can handle on the JS side. I reviewed the blog post about [SBG](https://www.nativescript.org/blog/static-binding-generator---what-is-it-good-for), but could not figure out how to override NativeScriptActivity in `MyActivity.js`. Doing the following\r\n````\r\ncom.tns.NativeScriptActivity.extend({\r\n    onCreate: function (bundle) {\r\n        this.super.onCreate(bundle);\r\n        console.log('overwrite');\r\n    }\r\n});\r\n````\r\n results in no `MyActivity.java` file being generated, and I get an error when the app loads.\r\n\r\nI also attempted the following\r\n````\r\nvar frameModule = require(\"ui/frame\");\r\nvar mainActivity = Object.assign({\r\n    onUserInteraction: function(){\r\n        console.log('user interaction');\r\n    }\r\n}, frameModule)\r\n\r\nandroid.app.Activity.extend(\"com.tns.MyActivity\", mainActivity);\r\n````\r\nwhich results in just a blank screen being displayed. I'm sure that both of these fail because the generator is static (of course). Just not sure how to get the desired result of overriding/adding to the default activity."}}
{"actor":{"display_login":"enchev"}}