AlarmManagerを使用して定期的に呼び出すサービスを1つ作成しました。私は同じコードを書いていますが、それは呼び出していません。私がAlarmManagerを通してBroadcasrRecieverを呼び出すと、正常に動作しています。以下はAlarmManagerを使用したコールサービス
私のサービスクラスは、
public class LocationUpdateService1 extends Service {
@Nullable
@Override
public IBinder onBind(Intent intent) {
Toast.makeText(getApplicationContext(), "I created", Toast.LENGTH_LONG);
return null;
}
}
マイmanifiestファイル、
<service
android:name=".Services.LocationUpdateService1">
</service>
が、私は私のサービスを呼び出すためにBroadcastReceiverクラスを作成しなければならないのである
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_home);
Intent alarmIntent = new Intent(this, LocationUpdateService1.class);
PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 0, alarmIntent, 0);
AlarmManager manager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
manager.setRepeating(AlarmManager.RTC_WAKEUP, 20000, 11000, pendingIntent);
}
、私のコードです? 私のコードで何が間違っていますか?それが定期的に呼び出されない理由は何ですか?
あなたは' PendingIntent.getService() 'を使用して' PendingIntent'を取得する必要があります。また、 'onBind()'は何かが 'Service'をバインドしない限り起動しません。おそらく 'onCreate()'や 'onStartCommand()'が必要でしょう。 –
[AlarmManagerでPendingIntent.getService()またはgetBroadcastを使用する必要がありますか?](http://stackoverflow.com/questions/7308298/should-i-use-pendingintent-getservice-or-getbroadcast-with-alarmmanager) –
getBroadcast()をgetService()に変更しましたが、まだ動作しません –