サービスをバインドしようとしていますが、onBind()
常に false を返します。
これはServiceConnection
-のコードです
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;
}
};
bindService()
これは-への呼び出しです
boolean test = getApplicationContext().bindService(new Intent(this, ScheduleService.class), mConnection, Context.BIND_AUTO_CREATE);
これは、マニフェストでのサービスの宣言です -
<service android:name=".Notifications.ScheduleService" android:enabled="true"/>
この件に関する以前の質問を読みましたが、答えが見つかりませんでした (アクティビティ コンテキストをアプリケーション コンテキストに切り替えようとしましたが、役に立ちませんでした)。
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();
}
}
どんな助けでも大歓迎です。ありがとう。