Domanda

I have an android app wherein the logger object is passed to the activity. The logger object takes care of pruning the log file and etc. Now, I have a requirement wherein I need to log the events from the service using the logger object/log file passed to the activity. I am scrutinizing the following solutions:

1) I found that one can pass objects from activity to service through parcelable intents. Can the logger object be passed to the service from the activity and be used?

2) Wrap the log contents within the service in an intent and pass the intent to the activity that holds a reference to the logger object. I am not sure about the size limit of intent and the performance overhead of passing intents every few milliseconds.

Is there a better way to solve this in android within the service oriented architecture?

È stato utile?

Soluzione

If the activity and service are in the same APK, you can just make the logger a singleton and do things the standard way of Java singletons (single instance held in a static variable in the class itself, usually accessed by a function called getInstance()).

Altri suggerimenti

you can try using event bus pattern and this library is made for android https://github.com/greenrobot/EventBus. You can pass objects between activity(fragments...)<-->services.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top