주 활동 (Home.java)의 알람 관리자를 사용하여 서비스 (NotificationService.java)를 시작하려고합니다. AlarmManager의 setInexactRepeating을 실행 한 후 로그를 저장하고 setInexactRepeating을 성공적으로 실행했음을 보여 주지만 서비스는 시작되지 않습니다. 매니페스트에 선언알람 관리자를 사용하여 서비스 시작하지 않음
여기public void startService(Context context){
AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
Intent i = new Intent(Home.this, NotificationService.class);
int minutes = 1 ;
PendingIntent pi = PendingIntent.getService(Home.this, 0, i, 0);
am.cancel(pi);
am.setInexactRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP,
System.currentTimeMillis(),
minutes*60*1000, pi);
Log.e("Service Started","Halilujia");
}
입니다 : 여기
이 서비스를 시작하는 코드 의견을 바탕으로 <service
android:name=".services.NotificationService"
android:enabled="true">
</service>
public class NotificationService extends Service {
private WakeLock mWakeLock;
private Context activity = getApplicationContext();
@Override
public IBinder onBind(Intent intent) {
return null;
}
private void handleIntent(Intent intent) {
// obtain the wake lock
PowerManager pm = (PowerManager) getSystemService(POWER_SERVICE);
mWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "DebuggingTag");
mWakeLock.acquire();
// check the global background data setting
ConnectivityManager cm = (ConnectivityManager) getSystemService(CONNECTIVITY_SERVICE);
if (!cm.getBackgroundDataSetting()) {
stopSelf();
return;
}
Log.e("Just before request","Just before Request");
// send http request here and create notification
}
@Override
public void onStart(Intent intent, int startId) {
Log.e("Onstart Called","Onstart has been Called");
handleIntent(intent);
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
Log.e("Onstart Called","Onstart has been Called");
handleIntent(intent);
return START_NOT_STICKY;
}
public void onDestroy() {
super.onDestroy();
mWakeLock.release();
}
}
감사
'AlarmManager.ELAPSED_REALTIME_WAKEUP'을'AlarmManager.RTC_WAKEUP'으로 변경해보십시오. – Squonk
작동하지 않았습니다. 당신은 그것의 경보 매니저를 생각하거나 서비스 자체 일 수 있 었는가? – Pacemaker
'onStartCommand (...) '메소드의 로그 메시지가 보입니까? – Squonk