here आधिकारिक मार्गदर्शिका द्वारा प्रदान किया गया कोड है, जबकि यह एक स्निपेट समस्या पैदा कर रहा है।एंड्रॉइड: Google API कनेक्शन को हल करने के लिए कैसे सेवा से विफल हो?
@Override
public void onConnectionFailed(ConnectionResult result) {
if (mResolvingError) {
// Already attempting to resolve an error.
return;
} else if (result.hasResolution()) {
try {
mResolvingError = true;
result.startResolutionForResult(this, REQUEST_RESOLVE_ERROR);
} catch (IntentSender.SendIntentException e) {
// There was an error with the resolution intent. Try again.
mGoogleApiClient.connect();
}
} else {
// Show dialog using GooglePlayServicesUtil.getErrorDialog()
mResolvingError = true;
GooglePlayServicesUtil.getErrorDialog(result.getErrorCode(), this, REQUEST_RESOLVE_ERROR)
.setOnDismissListener(new DialogInterface.OnDismissListener() {
@Override
public void onDismiss(DialogInterface dialog) {
mResolvingError = false;
}
});
}
}
अगर मैं एक सेवा, में इसका इस्तेमाल करते हैं जब आप चर this
उन कार्यों के लिए तर्क के रूप में पारित कर दिया पढ़ते हैं, वे एक गतिविधि प्रकार की उम्मीद है। मुझे कैसे करना चाहिए? यह एक सेवा है।
इसी कारण मैं गतिविधि परिणाम
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == REQUEST_RESOLVE_ERROR) {
mResolvingError = false;
if (resultCode == RESULT_OK) {
// Make sure the app is not already connected or attempting to connect
if (!mGoogleApiClient.isConnecting() &&
!mGoogleApiClient.isConnected()) {
mGoogleApiClient.connect();
}
}
}
}
इसलिए आपकी समस्या किसी गतिविधि का संदर्भ प्राप्त कर रही है ?? सेवा के जीवनकाल में गतिविधियों भी जीवित है? – Elltz
किस प्रकार की सेवा: शुरू, बाध्य, इरादा? –
तब शुरू हुआ जब गतिविधि किसी भी राज्य में हो सकती है – user3290180