Issue
I have some utils and workers in my project. All of these classes works as singleton. Suppose that I have multimple activities where this objects used but is there a difference between
private LocationWorker mLocationWorker;
...
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_daily_forecast);
mLocationWorker = LocationWorker.getInstance();
and this?
LocationWorker mLocationWorker = LocationWorker.getInstance()
It's okay to get references to this objects before onCreate() method?
Solution
It's okay to get references to this objects before onCreate() method?
Yes it is.
LocationWorker mLocationWorker = LocationWorker.getInstance();
should work fine.
However, since it is a singleton, I'm not sure there's much point saving a reference to it in a field. You could just do
LocationWorker.getInstance()
whenever you need it.
Answered By - Paul Boddington
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.