-
-
Notifications
You must be signed in to change notification settings - Fork 142
Custom Activity onSaveInstance crash #1004
Description
From @jogboms on April 13, 2018 7:50
Dear friend, we, the rest of the NativeScript community really
appreciate your feedback! While we are doing all we can to take care of every
issue, sometimes we get overwhelmed. Because of that, we will consider issues
that are not constructive or problems that cannot be reproduced "dead".
Additionally, we will treat feature requests or bug reports with unanswered
questions regarding the behavior/reproduction for more than 20 days "dead". All
"dead" issues will get closed.
Please, provide the details below:
Did you verify this is a real problem by searching the NativeScript Forum and the other open issues in this repo? yes
Tell us about the problem
Please, ensure your title is less than 63 characters long and starts with a capital
letter.
I created a custom activity in my {N} application. Everything works fine during development but i started noticing a crash in production involving the onSaveInstanceState method. I could attach the log if neccessary but here is a trimmed down version of it.
Calling js method onSaveInstanceState failed
Error: Cannot convert object to Landroid/util/SparseArray; at index 0
Which platform(s) does your issue occur on?
Android
Please provide the following version numbers that your issue occurs with:
- CLI: (run
tns --versionto fetch it)3.4.3 - Cross-platform modules: (check the 'version' attribute in the
node_modules/tns-core-modules/package.jsonfile in your project)3.4.1 - Runtime(s): (look for the
"tns-android"and"tns-ios"properties in the
package.jsonfile of your project)3.4.2 - Plugin(s): (look for the version number in the
package.jsonfile of your
project)
Please tell us how to recreate the issue in as much detail as possible.
The best approach would be to get your code running in the NativeScript Playground and share the link with us, along with any additional details or steps to reproduce needed for examining the issue there.
Is there code involved? If so, please share the minimal amount of code needed to recreate the problem.
import { AndroidActivityCallbacks, setActivityCallbacks } from "ui/frame";
import { ReplaySubject } from "rxjs/ReplaySubject";
import { Observable } from "rxjs/Observable";
const _intentSubject = new ReplaySubject<android.content.Intent>();
export const onNewIntent: Observable<android.content.Intent> = _intentSubject.asObservable();
@JavaProxy("com.test.TestActivity")
class Activity extends android.app.Activity {
private _callbacks: AndroidActivityCallbacks;
onCreate(savedInstanceState: android.os.Bundle): void {
if (!this._callbacks) {
setActivityCallbacks(this);
}
this._callbacks.onCreate(this, savedInstanceState, super.onCreate);
const creationIntent = this.getIntent();
_intentSubject.next(creationIntent);
}
onNewIntent(intent: android.content.Intent): void {
super.onNewIntent(intent);
this.setIntent(intent);
_intentSubject.next(intent);
}
protected onSaveInstanceState(outState: android.os.Bundle): void {
this._callbacks.onSaveInstanceState(this, outState, super.onSaveInstanceState);
}
protected onStart(): void {
this._callbacks.onStart(this, super.onStart);
}
protected onStop(): void {
this._callbacks.onStop(this, super.onStop);
}
protected onDestroy(): void {
this._callbacks.onDestroy(this, super.onDestroy);
}
public onBackPressed(): void {
this._callbacks.onBackPressed(this, super.onBackPressed);
}
public onRequestPermissionsResult(requestCode: number, permissions: Array<String>, grantResults: Array<number>): void {
this._callbacks.onRequestPermissionsResult(this, requestCode, permissions, grantResults, undefined /*TODO: Enable if needed*/);
}
protected onActivityResult(requestCode: number, resultCode: number, data: android.content.Intent): void {
this._callbacks.onActivityResult(this, requestCode, resultCode, data, super.onActivityResult);
}
}Copied from original issue: NativeScript/NativeScript#5673