1

I used a receiver which would start a service on boot. In the services onCreate i put in a scheduled alarm. This is only executed once. Why? Here is the code for the service which is called by the receiver on boot

/**
 * Created by rishabh on 24/3/16.
*/
public class MyServiceOnBoot extends Service {
@Nullable
@Override
public IBinder onBind(Intent intent) {
    return null;
}
@Override
public void onCreate(){
    Calendar c=Calendar.getInstance();
    Intent intent2 = new Intent(MyServiceOnBoot.this,MyABService.class);
    PendingIntent pintent = PendingIntent.getService(MyServiceOnBoot.this, 0, intent2, 0);
    AlarmManager alarm_manager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
    alarm_manager.setRepeating(AlarmManager.RTC, c.getTimeInMillis(), 1*1000,  pintent);
    stopSelf();
}
}

The MyABService class is only executed once. What could be the solution for it? Here is the receiver class

public class MyReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
    Intent startServiceIntent = new Intent(context, MyServiceOnBoot.class);
    context.startService(startServiceIntent);
}
}

Here is the Manifest

  <service android:name=".MyABService"/>
    <receiver android:name="com.todaysfuture.dynpin.MyReceiver">
        <intent-filter>
            <action android:name="android.intent.action.BOOT_COMPLETED" />
        </intent-filter>
    </receiver>
AxeManTOBO
  • 487
  • 1
  • 4
  • 17

0 Answers0