stsaz / phiola

Fast audio player, recorder, converter for Windows, Linux & Android
BSD 2-Clause "Simplified" License
119 stars 7 forks source link

New MainActivity created but no onDestroy() is called #13

Closed neoedmund closed 9 months ago

neoedmund commented 10 months ago

Android app Reproducing: 1) play a audio 2) switch the task out 3) click the service notifier to bring out the activity again then a new MainActivity is created but the older one's onDestory() is not called Why this is bad is the filter grows 1 extra MainActivity every time.

Also there is 2 filters created within Svc, which should not be intented.

this may result in some unexpected bug.

I have tweaked the Svc.java by alot of methods find on the net but no luck.

I'm going to roll out my own fix in my fork. Hope you will also have a look into this problem.

Thanks

stsaz commented 10 months ago

a new MainActivity is created but the older one's onDestory() is not called

I don't understand why would Android create 2 instances of MainActivity class inside the same system process. In my understanding the system will call onStart() callback when the user returns to the activity, as shown here: https://developer.android.com/guide/components/activities/activity-lifecycle#alc

However, if indeed that is the case, it looks like we can move some code out of onDestroy() callback into onStop() - this will remove the link between Core and old MainActivity. But first it's good to understand what exactly is happening here, step by step. I'll check this on my device.

this may result in some unexpected bug.

Is there some kind of crash (exception) here? Can you attach debug logs so I can look closer into it?

neoedmund commented 10 months ago

Is there some kind of crash (exception) here? Can you attach debug logs so I can look closer into it?

No error observed about this yet.

May you also to confirm that Svc.java created 2 filter into the filters ?

neoedmund commented 10 months ago

I'm giving up to understand Android, Instead I made a workaround , see https://github.com/neoedmund/phiola/blob/beta/android/phiola/src/main/java/com/github/stsaz/phiola/Track.java#L303 It fixed all the problem even multi MainActivity are created, especially about Lyrics, which need to find the correct MainActivity's view to show the lyrics.

stsaz commented 9 months ago

Nothing to do here from my side currently. Please reopen in case you have some new info on this.