Skip to content

Commit abb0b74

Browse files
authored
Merge pull request NativeScript#1901 from NativeScript/NathanaelA-patch-1
Update extend-application-activity.md
2 parents 17fcf3a + 1f87959 commit abb0b74

File tree

1 file changed

+43
-33
lines changed

1 file changed

+43
-33
lines changed

docs/core-concepts/android-runtime/advanced-topics/extend-application-activity.md

Lines changed: 43 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -109,39 +109,49 @@ The core modules ship with a default `androidx.appcompat.app.AppCompatActivity`
109109
110110
const superProto = androidx.appcompat.app.AppCompatActivity.prototype;
111111
androidx.appcompat.app.AppCompatActivity.extend("org.myApp.MainActivity", {
112-
onCreate: function(savedInstanceState) {
113-
// Set the isNativeScriptActivity in onCreate (as done in the original NativeScript activity code)
114-
// The JS constructor might not be called because the activity is created from Android.
115-
this.isNativeScriptActivity = true;
116-
if(!this._callbacks) {
117-
frame.setActivityCallbacks(this);
118-
}
119-
// Modules will take care of calling super.onCreate, do not call it here
120-
this._callbacks.onCreate(this, savedInstanceState, this.getIntent(), superProto.onCreate);
121-
122-
// Add custom initialization logic here
123-
},
124-
onSaveInstanceState: function(outState) {
125-
this._callbacks.onSaveInstanceState(this, outState, superProto.onSaveInstanceState);
126-
},
127-
onStart: function() {
128-
this._callbacks.onStart(this, superProto.onStart);
129-
},
130-
onStop: function() {
131-
this._callbacks.onStop(this, superProto.onStop);
132-
},
133-
onDestroy: function() {
134-
this._callbacks.onDestroy(this, superProto.onDestroy);
135-
},
136-
onBackPressed: function() {
137-
this._callbacks.onBackPressed(this, superProto.onBackPressed);
138-
},
139-
onRequestPermissionsResult: function (requestCode, permissions, grantResults) {
140-
this._callbacks.onRequestPermissionsResult(this, requestCode, permissions, grantResults, undefined);
141-
},
142-
onActivityResult: function (requestCode, resultCode, data) {
143-
this._callbacks.onActivityResult(this, requestCode, resultCode, data, _super.prototype.onActivityResult);
144-
}
112+
onCreate: function(savedInstanceState) {
113+
// Used to make sure the App is inited in case onCreate is called before the rest of the framework
114+
appModule.android.init(this.getApplication());
115+
116+
// Set the isNativeScriptActivity in onCreate (as done in the original NativeScript activity code)
117+
// The JS constructor might not be called because the activity is created from Android.
118+
this.isNativeScriptActivity = true;
119+
if(!this._callbacks) {
120+
frame.setActivityCallbacks(this);
121+
}
122+
// Modules will take care of calling super.onCreate, do not call it here
123+
this._callbacks.onCreate(this, savedInstanceState, this.getIntent(), superProto.onCreate);
124+
125+
// Add custom initialization logic here
126+
},
127+
onNewIntent: function (intent) {
128+
this._callbacks.onNewIntent(this, intent, superProto.setIntent, superProto.onNewIntent);
129+
},
130+
onSaveInstanceState: function(outState) {
131+
this._callbacks.onSaveInstanceState(this, outState, superProto.onSaveInstanceState);
132+
},
133+
onStart: function() {
134+
this._callbacks.onStart(this, superProto.onStart);
135+
},
136+
onStop: function() {
137+
this._callbacks.onStop(this, superProto.onStop);
138+
},
139+
onDestroy: function() {
140+
this._callbacks.onDestroy(this, superProto.onDestroy);
141+
},
142+
onPostResume: function () {
143+
this._callbacks.onPostResume(this, superProto.onPostResume);
144+
},
145+
onBackPressed: function() {
146+
this._callbacks.onBackPressed(this, superProto.onBackPressed);
147+
},
148+
onRequestPermissionsResult: function (requestCode, permissions, grantResults) {
149+
this._callbacks.onRequestPermissionsResult(this, requestCode, permissions, grantResults, undefined);
150+
},
151+
onActivityResult: function (requestCode, resultCode, data) {
152+
this._callbacks.onActivityResult(this, requestCode, resultCode, data, superProto.onActivityResult);
153+
}
154+
/* Add any other events you need to capture */
145155
});
146156
```
147157
```typescript

0 commit comments

Comments
 (0)