izivkov/CasioGShockSmartSync

Background Service

G-OD opened this issue · 8 comments

G-OD commented

I was thinking it'd probably be a cool idea to have a background service, mostly for the phone finding feature. I realised that while I was testing out this feature that it wasn't working very well if you forget to open the app or if the app decided to sleep.

If you had some brief idea as to how this would work I could start off the PR however I have limited Kotlin experience and it has been years since I've touched android development.

@G-OD, thanks for creating this issue.

The short answer to how to add this service is to uncomment these 2 lines. You can uncomment and test if it works for you, since I have not tested thoroughly. Also, you may have an alternative, better way to do this, so try and let me know how it goes.

As you can see, we had this implemented at one time. However, there are a number of issues doing that:

  • The app uses more memory. This is one of the major complaints people have with the official app.
  • The app is always "in your face." People do not like that.
  • I feel that Android is trying to discourage developers from keeping services running in the background, and this is why people come up with these hacks.

So, we have disabled this feature. I know that always running the app in foreground/background has some legitimate advantages. In addition to "Find Phone", "Auto time adjustment" does not work after the app has been swapped out of memory. On balance, I feel the negatives outweigh the positives, and this is why we disabled it.

Another way to accomplish keeping the app in memory is to use a 3rd party app like Tasker or MacroDroid.

Now, having said that, I am open to giving the user an option to run the app in the background, but this should not be the default behaviour, and should be configurable in the settings.

So, I think we can start by testing if uncommenting the code I mentioned above works well for you. The next step would be to think if we can add this option to settings.

Regards

BTW, I like your handle. I guess GOD was taken by somebody already.

G-OD commented

Okay that's understandable. I took a look at the code and noticed there was a service already while looking into creating my own temporary solution so it's nice to get context as to why it's not in use. I'll definitely look into enabling this and see how it goes.

Also thanks. This name is actually my initials so it's not there for the reasons you may think although I obviously made it like this on purpose haha.

I agree that adding an option for keeping the app running in the background would be good. The fact that the app have to be reopened regularly on the phone before being abke to interact with the watch is the only reason why I keep using the official app...

@G-OD So, dies it work for you when you uncommented the background service?

G-OD commented

I had issues with it. I think it's because the background service needs to do the bluetooth connection as the main activity cannot run while in the background? I'm mostly just guessing as Android development isn't my main forte. I tried changing the foreground service type to "connectedDevice" and added the permission "FOREGROUND_SERVICE_CONNECTED_DEVICE". I also tried modifying the service to search bluetooth in the background like what's done in the MainActivity but that didn't work either so maybe someone who actually knows how to use these APIs could do a better job then me.

I am closing this is issue. Will reopen if I, or somebody else can come up with a good solution.