मेरे पास यह सरल सेवा है जो उपयोगकर्ता के वर्तमान स्थान को प्रसारित करती है। मैं सेवा जीवन चक्र को नियंत्रित करने के लिए बाध्यकारी तंत्र का उपयोग करना चाहता हूं, लेकिन सेवा अभी शुरू नहीं हो रही है।सेवा के बाद सेवा (या कनेक्टिंग) नहीं बनाई जा रही है()
मैंने क्या गलत किया?
public class GPSActivity extends ListActivity {
...
protected void onResume() {
super.onResume();
Log.i("Service", "Service bound");
Intent intent = new Intent(this, LocationService.class);
bindService(intent, service_connection , Context.BIND_AUTO_CREATE);
}
protected void onPause() {
if (dataUpdateReceiver!=null)
unregisterReceiver(dataUpdateReceiver);
unbindService(service_connection);
super.onPause();
}
class LocationServiceConnection implements ServiceConnection{
public void onServiceConnected(ComponentName name, IBinder service) {
Log.i("Service", "Service Connected");
}
public void onServiceDisconnected(ComponentName name) {
}
}
}
LocalBinder.java
public class LocalBinder<S> extends Binder {
private String TAG = "LocalBinder";
private WeakReference<S> mService;
public LocalBinder(S service){
mService = new WeakReference<S>(service);
}
public S getService() {
return mService.get();
}
}
LocationService.java
public class LocationService extends Service {
public void onCreate() {
initLocationListener();
Log.i("Location Service","onCreate()");
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
Log.i("Location Service", "Received start id " + startId + ": " + intent);
return START_NOT_STICKY;
}
private final IBinder mBinder = new LocalBinder<LocationService>(this);
@Override
public IBinder onBind(Intent intent) {
return mBinder;
}
}
AndroidManifest.xml
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
...
<service android:name=".LocationService">
</service>
</application>
संपादित करें: निकट के जवाब के लिए निश्चित धन्यवाद।
प्रकट प्रविष्टि एक लक्ष्य फ़िल्टर या सही नाम
<service
android:enabled="true"
android:name="com.android.gps.services.LocationService">
<intent-filter>
<action android:name="com.android.gps.services.LocationService" />
</intent-filter>
</service>
और आशय मैं बाध्यकारी हैं जिन्हें आप जब एक गतिविधि शुरू करने उपयोग करने की आवश्यकता की तरह था के लिए इस्तेमाल किया नहीं था। सही एक है:
Intent intent = new Intent("com.android.gps.services.LocationService");
क्या आपके 'सार्वजनिक IBinder onBind (आशय आशय)' में विधि 'LocationService.java' कैसा दिखता है? – Jens
@ जेन्स मैंने ऑनबिंड() विधि को शामिल करने के लिए प्रश्न संपादित किया। – bughi
एचएम। और आपको 'Log.i ("स्थान सेवा", "ऑनक्रेट()") भी नहीं मिल रहा है;' अपने लॉगकैट में लॉग इन करें? – Jens