Skip to content

Commit 4404716

Browse files
committed
Patch livesync to avoid crashes on "page reload" syncs.
1 parent 62aa23f commit 4404716

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

app/livesync-patch.ts

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import * as application from "application";
2+
3+
4+
global.__onLiveSync = function() {
5+
if (application.android) {
6+
//Force an app restart even for page reload livesyncs
7+
const android = global.android;
8+
const System = global.java.lang.System;
9+
const Context = android.content.Context;
10+
const Intent = android.content.Intent;
11+
const PendingIntent = android.app.PendingIntent;
12+
const AlarmManager = android.app.AlarmManager;
13+
14+
const context = application.android.context;
15+
const launchIntent = context.getPackageManager().getLaunchIntentForPackage(context.getPackageName());
16+
17+
launchIntent.addFlags(
18+
Intent.FLAG_ACTIVITY_CLEAR_TOP |
19+
Intent.FLAG_ACTIVITY_CLEAR_TASK |
20+
Intent.FLAG_ACTIVITY_NEW_TASK
21+
);
22+
const pendingIntent = PendingIntent.getActivity(context, 123456, launchIntent,
23+
PendingIntent.FLAG_CANCEL_CURRENT);
24+
25+
const alarmManager = context.getSystemService(Context.ALARM_SERVICE);
26+
alarmManager.set(AlarmManager.RTC, System.currentTimeMillis(), pendingIntent);
27+
28+
android.os.Process.killProcess(android.os.Process.myPid());
29+
} else {
30+
console.log("Single page update syncs not supported.");
31+
}
32+
}

app/main.ts

+1
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,6 @@ import {nativeScriptBootstrap} from "nativescript-angular/application";
22
import {HTTP_PROVIDERS} from "angular2/http";
33
import {NS_ROUTER_PROVIDERS} from "nativescript-angular/router";
44
import {AppComponent} from "./app.component";
5+
import "./livesync-patch";
56

67
nativeScriptBootstrap(AppComponent, [HTTP_PROVIDERS, NS_ROUTER_PROVIDERS]);

0 commit comments

Comments
 (0)