How can I pass a LocationClient through an intent and when the abstract methods are present in the main activity?

StackOverflow https://stackoverflow.com/questions/20986389

سؤال

LocationClient(Context context,
    GooglePlayServicesClient.ConnectionCallbacks connectionCallbacks, 
    GooglePlayServicesClient.OnConnectionFailedListener connectionFailedListener)

This is usually called as:

LocationClient LC = new LocationClient(this, this, this);

The problem with this is that it treats the current activity as the context, and ConnectionCallbacks and OnConnectionFailedListener require abstract methods. I want to be able to create this client in my main activity, then pass it to one of various other activities that the user can go to. Am I able to pass this as a parcelable in an intent? What will happen to the abstract methods created in the main activity? Is there a standard for doing this or do you know of any better ways to handle this, or does it make more sense just to make a new LocationClient in each activity?

هل كانت مفيدة؟

المحلول

LocationClient is not Parcelable so you cannot pass it through an intent.

Typically you only want or need one LocationClient per application, not per activity, so I wouldn't create one in each activity.

That leaves you with the option to create it in your Application class. The Application also derives from Context so this should not present any problem.

You can read about deriving your own Application class here or elsewhere.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top