Best practise question about passing information between Activity and Service
I have a question about best practise.
I have an Activity which is a form where the user fills in some details. There is a tick box which, if ticked will run a Service开发者_C百科 which will attempt to get a location.
If the activity is close (onDestroy) I write to a static boolean in a static class that this has happened.
When my Service gets a location it checks this static variable to see if it should pass the location back to the Activity (via a Handled Message). This bit works fine.
If the Activity has been saved to my database I need to give my service the row id so that it can update the database entry rather than pass the location back to the activity.
I decided, based on my limited Java and Android knowledge, to use another static field in my helper class which I can set with the rowID in my Activity. I can then access this rowid in my Service and go and get the database entry and update it. I am pretty sure that this will work but I am not sure it is appropriate
Any tips and advice would be appreciated, although 'that's not a good way to do it' with no other information is useless advice :)
Regards Stephen
This guy has written an amazing tutorial: http://mindtherobot.com/blog/675/android-architecture-message-based-mvc/#more-675
精彩评论