-1

I wont start service at specific time everyday and also start when the device boot complete.

For example.. at 13.00 Pm everyday the service started and show a Toast ("Service started").

not only that, but the service has to start also at boot complete but if you are not the 13.00 pm should not show the toast but must started

Cœur
  • 37,241
  • 25
  • 195
  • 267
Edoardo Goffredo
  • 303
  • 2
  • 5
  • 20

3 Answers3

0

For boot complete define receiver for ACTION_BOOT_COMPLETED Start service at boot complete

For Specific time, use AlarmManager Start Service At Specific Time

Community
  • 1
  • 1
Ajit
  • 724
  • 7
  • 16
0
public class onBootComplete extends BroadcastReceiver{

    @Override
    public void onReceive(Context context, Intent intent) {
        // TODO Auto-generated method stub
         if (intent.getAction().equals(Intent.ACTION_BOOT_COMPLETED)){
                //Do your task here
            }
    }

}

And in Manifest declare this..

<receiver
            android:name=".onBootComplete"
            android:enabled="true"
            android:exported="true" >
            <intent-filter android:priority="500" >
                <action android:name="android.intent.action.BOOT_COMPLETED" />
            </intent-filter>
        </receiver>

Add this permission:

<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>

For timed actions use AlarmManager

This class provides access to the system alarm services. These allow you to schedule your application to be run at some point in the future. When an alarm goes off, the Intent that had been registered for it is broadcast by the system, automatically starting the target application if it is not already running.

Thickar
  • 171
  • 1
  • 8
0

check this link ,it will help you How to repeat notification daily on specific time in android through background service

Community
  • 1
  • 1
Mohit Madaan
  • 469
  • 2
  • 11