Skip to main content

schedule()

Schedules a task to run repeatedly based on a cron expression. Perfect for recurring automations like posting content, checking notifications, or performing maintenance.
string
required
JavaScript code to execute. Can be a single statement or a function call.
string
required
Cron expression defining when the task runs. Format: second minute hour day month dayOfWeek
void
The task is registered and will run according to the schedule.

Basic Usage

Cron Expression Format

Cron expressions use 6 fields:

Common Cron Patterns

Practical Examples

Implementation Details

Source Location

MainActivity.kt:5488

Task Storage

Scheduled tasks are:
  • Persisted to SharedPreferences
  • Survive app restarts
  • Checked by a background cron checker thread
  • Assigned unique IDs for management
Tasks execute on a scheduled executor service with 2 threads. Long-running tasks should be avoided.

clearSchedule()

Removes all scheduled tasks. Useful for resetting automation state or clearing old schedules.
void
All scheduled tasks are cleared and removed from storage.

Usage

Implementation

MainActivity.kt:5525

Complete Examples

Instagram Posting Bot

Email Digest

Status Checker

Best Practices

Scheduled tasks should call functions rather than containing complex inline code.
Errors in scheduled tasks should be caught and handled gracefully.
Very frequent tasks (every second) can drain battery and CPU.
Prevent duplicate tasks by clearing before scheduling.

Viewing Scheduled Tasks

Scheduled tasks appear in the PhoneClaw UI:
  1. Open the PhoneClaw app
  2. Navigate to the Scheduled Tasks tab
  3. View all active tasks with their cron expressions
  4. See last execution time and next scheduled time

Limitations

  • Maximum of 100 concurrent scheduled tasks
  • Tasks must complete before the next scheduled execution
  • Long-running tasks (>5 minutes) may be terminated
  • Schedule persists but execution pauses if device is off
  • Requires app to remain running in background