0

I'm newbie in Android services and I need some help. I'm trying to understand the google's guide, but it really lacks lot's of information and i hate the fact that google automaticly translates to my language and doesn't allow me to DENY it, so i cant quote it here.

https://developer.android.com/guide/components/services

I've an app that perform long tasks on background, so I do understand that i need a service to achieve that since activities and related thread or resources might be killed by android when the app goes background.

My service monitore some stuff from user social media so i do need to use social media Apis to contact with their server. To make things easier i wrap the social media apis into one facade and my service deals only with that facade. this facade is a singleton

the user logs in-> the service starts to run in background -> at certain point the user leaves the app now starts the problem...

after the user left the app, my background service keeps running: OK
all its fields still aren't collected by GC: OK but the inner fields of the facade singleton get released by GC and at certain point my service call singleton (not null) which calls some field that now is null: PROBLEM

how can i deal with that? how can i force android to keep those fields (aren't many) alive because they are being used by my service

PLEASE- do not ask me to make them parceable or something like this... it is a third party api i cant change

Rafael Lima
  • 3,079
  • 3
  • 41
  • 105
  • "facade"... I think that is a mistranslation, perhaps of "interface". At any rate, GC doesn't "run around setting fields to null". Your code must've done that (assuming these are pure Java references). You may want to try using a [data breakpoint](https://stackoverflow.com/a/30820630/6759241) to determine what's causing the change. – greeble31 Dec 03 '18 at 21:23
  • "facade" means "facade" this is an english term and a design pattern... And GC do set fields to null. It is supposed to not set the current in use fields, but android VM does manage what it consider "in use" so an app in background isn't in use and pehaps has it's fields collected... even static ones – Rafael Lima Dec 04 '18 at 12:26
  • what does programming courses teach students nowadays? https://en.wikipedia.org/wiki/Facade_pattern. Facade should be one of the most well known pattern... it is basics – Rafael Lima Dec 04 '18 at 12:28

0 Answers0