मैं एक सेवा बांधने की कोशिश कर रहा हूं, लेकिन onBind()
हमेशा झूठा रिटर्न देता है। है bindService()
करने के लिए कॉलऑनबिंड() सेवा पर हमेशा झूठी रिटर्न - एंड्रॉइड
private ServiceConnection mConnection = new ServiceConnection() {
public void onServiceConnected(ComponentName className, IBinder service) {
// This is called when the connection with our service has been established,
// giving us the service object we can use to interact with our service.
mBoundService = ((ScheduleService.ServiceBinder) service).getService();
}
public void onServiceDisconnected(ComponentName className) {
mBoundService = null;
}
};
इस - -
boolean test = getApplicationContext().bindService(new Intent(this, ScheduleService.class), mConnection, Context.BIND_AUTO_CREATE);
यह प्रकट में सेवा की घोषणा है -
इस के लिए ServiceConnection
कोड है
<service android:name=".Notifications.ScheduleService" android:enabled="true"/>
मैंने विषय के बारे में पिछले प्रश्न पढ़े हैं और एक उत्तर नहीं मिला wer (गतिविधि संदर्भ के साथ गतिविधि संदर्भ स्विच करने की कोशिश की, लेकिन यह मदद नहीं की)।
मैं Frgaments और ActionBarSherlock का उपयोग कर उपयोग कर रहा हूं, और मेरी गतिविधि SlidingFragmentActivity
फैली हुई है (यही कारण है कि मैं एप्लिकेशन संदर्भ का उपयोग कर रहा हूं, जो मदद नहीं करता है)।
संपादित करें -
public class ScheduleService extends Service {
/**
* Class for clients to access
*/
public class ServiceBinder extends Binder {
public ScheduleService getService() {
return ScheduleService.this;
}
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
Log.i("ScheduleService", "Received start id " + startId + ": " + intent);
// We want this service to continue running until it is explicitly stopped, so return sticky.
return START_STICKY;
}
@Override
public IBinder onBind(Intent intent) {
return mBinder;
}
// This is the object that receives interactions from clients. See
private final IBinder mBinder = new ServiceBinder();
/**
* Show an alarm for a certain date when the alarm is called it will pop up a notification
*/
public void setAlarm(Calendar c) {
// This starts a new thread to set the alarm
// You want to push off your tasks onto a new thread to free up the UI to carry on responding
new AlarmTask(this, c).run();
}
}
किसी भी मदद की सराहना की जाएगी - यह मैं शुरू करने के लिए कोशिश कर रहा हूँ सेवा के कोड है। धन्यवाद।
मुझे लगता है कि आपको मैनिफेस्ट में .Notifications को हटा देना चाहिए। –
अपनी सेवा कार्यान्वयन कोड पोस्ट करें। – yorkw
मैंने कार्यान्वयन के साथ प्रश्न संपादित किया। – Tofira