-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
feat: delay the launch event until the app becomes active #9906
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
4888e9c
to
9a81cd7
Compare
wouldnt it be better to add a new event? for me launched is when native application object is created. that change could break some logic, or make app slower. adding a displayed event would be a good addition |
@farfromrefug in Android, the launch event is called when the Activity has launched, not the Application. This would also mean that flavors would have to handle different events for android/ios as well, as currently the launch event is the correct place to set the root view, but on iOS this happens before we even know that the app will need a root view. So we either add a breaking change that the launch event is now NOT the correct way of creating the UI (and remove So you'd need something like:
|
@edusperoni i get your point.
|
on iOS, application is available from the start (before Application.run). On Android, it's available directly after Application.run (I've talked with @rigor789 and we'll most likely refactor it to make it available from the start as well). Android has an 'activityCreated' event that you can use to get the startActivity/currentActivity if they're missing. Currently, this code is inconsistent:
As this code won't run on android if it's launched from the background. On android there's also no way of getting the application context without a setTimeout or placing the code after Application.run(). I believe the less disruptive change is to make launch event run delayed on iOS, as if you make it run earlier on Android, it'll break quite a few things that depend on Maybe we can do:
Naming is a bit hard. Launch could make more sense as the initial event, but I think it's too disruptive on android, as launch/exit events were always tied to the UI lifecycle (activity). They'd be called multiple times on android 11- if you left the app with the back button, for example. All integrations also use launch/exit for their UI creation/cleanup (apart from maybe vanilla). This PR doesn't actually change the behavior for non-background apps, though, as didBecomeActive is called right after didFinishLaunchingWithOptions. |
@edusperoni just to point out the current behavior of launch on android when run from the background is totally fine for me. and always was. it is doing what it i think it is supposed to. if the app is in background you dont need to re initialize (like sentry for example) |
On android 11- the launch event is called multiple times (open app, launch is called, use back button, exit is called, open app again, launch is called). The idea of this PR is to make both iOS and Android behave the same way. iOS and Android 12+ will never call exit event though, only launch a single time (on android, only if the app has been opened in the foreground, will never be called when receiving a firebase data notification for example) Edit: |
This seems to be causing some confusion. Let me clarify it a bit: // main.ts
console.log('Starting main.ts');
firebase()
.messaging()
.onMessage((remoteMessage) => {
console.log('received firebaseMessage');
});
Application.on('launch', (args) => {
console.log('launch event');
// initialize some native API
const rootView = new GridLayout();
rootView.on('loaded', () => console.log('rootView loaded');
args.root = rootView;
});
Application.run();
console.log('end main.ts'); Android AND iOS, tapping the app icon to open the app
Android, receiving a data notification from the background:
iOS, receiving a data notification from the background
If you assume the user never launches the app (which is the case most of the time), then you'll have executed the full launch event without the need to, which includes creating all the views, and most likely doing initial network requests like the app is starting (on angular's case, it bootstraps the app completely, so if you're doing any kind of ngOnInit or using ngrx effects or whatever, it'll all fire). Proposed change (both platforms): tapping the app icon to open the app
background notification
this is a subtle change that will only affect if you're using some kind of background execution on your app where it won't fire a ton of requests on iOS when all you do is receive a push notification. |
@edusperoni ok I understand I think it is the same issue as the loaded event for views. people use it to trigger web request but it is called far too many times in an app life cycle. think it is the same with launch event. |
Just a question that is semi related, which application event do you guys recommand to init Sentry on? |
On iOS you can initialize right away, I'm initializing after Application.run on Android (or in my case runNativeScriptApp). Soon you should be able to initialize anywhere on Android (once we change so that we don't need application.run to set the native android app) |
This is a draft/discussion PR.
According to the iOS docs, the UI should be built on
didBecomeActive
instead ofdidFinishLaunchingWithOptions
. This makes a difference when we launch the application due to a fetch event or firebase message, asdidFinishLaunchingWithOptions
will launch with the app in the background and no UI will be shown unless the user opens the app manually in the meantime.The same scenario on Android delays the launchEvent until the app opens. This PR would make both platforms behave the same.
Checklist:
didFinishLaunchingWithOptions
didFinishLaunchingWithOptions
BREAKING CHANGE:
On iOS, the following flow would happen on background launch (app receives a push or is awaked for background fetch):
Now, it follows the same flow as android:
This means that receiving a notification is now much more lightweight if the user doesn't open the app immediately