Stop activity if we cant start node
Currently when receiving a push notification while the app has not started (on android), the whole app is woken up. If autologin is enabled, we will try to start the node, but will fail has no activity has been attached. In such cases we try for 10s and quit the app if not successful. Signed-off-by: Andrea Maria Piana <andrea.maria.piana@gmail.com>
This commit is contained in:
parent
8f40f796f5
commit
530a6dca2e
|
@ -90,12 +90,25 @@ class StatusModule extends ReactContextBaseJavaModule implements LifecycleEventL
|
|||
}
|
||||
|
||||
private boolean checkAvailability() {
|
||||
// We wait at least 10s for getCurrentActivity to return a value,
|
||||
// otherwise we give up
|
||||
for (int attempts = 0; attempts < 100; attempts++) {
|
||||
if (getCurrentActivity() != null) {
|
||||
return true;
|
||||
return true;
|
||||
}
|
||||
try {
|
||||
Thread.sleep(100);
|
||||
} catch (InterruptedException ex) {
|
||||
if (getCurrentActivity() != null) {
|
||||
return true;
|
||||
}
|
||||
Log.d(TAG, "Activity doesn't exist");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
Log.d(TAG, "Activity doesn't exist");
|
||||
return false;
|
||||
Log.d(TAG, "Activity doesn't exist");
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
|
@ -342,6 +355,7 @@ class StatusModule extends ReactContextBaseJavaModule implements LifecycleEventL
|
|||
Log.d(TAG, "startNode");
|
||||
if (!checkAvailability()) {
|
||||
Log.e(TAG, "[startNode] Activity doesn't exist, cannot start node");
|
||||
System.exit(0);
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue