Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Automatic Task in a specific time

Tags:

android

I am new in Android development. I am developing a twitter client. I would like to send a tweet at every morning at 8. I want to set the schedule like Alarm. How can I do that ? I will be happy if you point me to some examples or other resources. Thanks.

like image 952
Kona Ahmed Avatar asked Dec 01 '25 04:12

Kona Ahmed


1 Answers

Here is an example of the AlarmManager:

private void daylyTask()
{
    daylyBR = new BroadcastReceiver() {
        @Override public void onReceive( Context context, Intent _ )
        {       
            //Do something
            Log.d(TAG, "daylyTask uitgevoerd.");
        }
    };

    getApplicationContext().registerReceiver( daylyBR, new IntentFilter("yourApp.blah") );


    daylyPendingIntent = PendingIntent.getBroadcast( getApplicationContext(), 0, new Intent("yourApp.blah"), 0 );

    GregorianCalendar cal = new GregorianCalendar();
    cal.set(GregorianCalendar.HOUR_OF_DAY, 0);
    cal.set(GregorianCalendar.MINUTE, 0);

    // set alarm to fire 5 sec (1000*5) from cal repeating every 86400000L ms (1 day)
    manager.setRepeating( AlarmManager. RTC_WAKEUP, cal.getTimeInMillis() + 5000L,  86400000L,  daylyPendingIntent );
}
like image 119
Robin Dijkhof Avatar answered Dec 02 '25 21:12

Robin Dijkhof



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!