Overview
PhoneClaw includes a cron-based task scheduler that enables automation scripts to run on recurring schedules. This allows you to automate posting, data scraping, monitoring, and other tasks without manual intervention.Architecture
Data Model
FromMainActivity.kt:152-159:
id: Unique UUID for the tasktaskDescription: JavaScript code or human-readable descriptioncronExpression: Cron schedule (simplified format)createdAt: Timestamp when task was createdlastExecuted: Last execution timestampisActive: Whether task should run
Scheduler Implementation
PhoneClaw uses Kotlin coroutines for lightweight background scheduling:Starting the Scheduler
FromMainActivity.kt:3497-3520:
The scheduler checks every 60 seconds to see if any tasks should execute. This provides minute-level scheduling precision.
Task Execution Logic
FromMainActivity.kt:3521-3555:
Cron Expression Format
PhoneClaw uses a simplified cron format:Supported Patterns
Every N seconds
Every N seconds
Every N minutes
Every N minutes
Every N hours
Every N hours
Once daily
Once daily
Expression Parser
FromMainActivity.kt:3556-3620:
The parser converts cron expressions to millisecond intervals. More complex expressions (specific days, months) are not currently supported.
Creating Scheduled Tasks
Via JavaScript API
Via Kotlin API
FromMainActivity.kt:3622-3633:
Via AndroidJSInterface
FromMainActivity.kt:5480-5530:
Persistence
Tasks are saved to SharedPreferences as JSON:Saving Tasks
Loading Tasks
UI Integration
PhoneClaw includes a modern UI for managing scheduled tasks:Task List Fragment
Task Management
Example Use Cases
Daily Social Media Posting
Periodic Data Scraping
System Monitoring
Automated Engagement
Best Practices
Battery Optimization: Android may kill background processes to save battery. Consider:
- Disabling battery optimization for PhoneClaw
- Using longer intervals (hourly vs. every minute)
- Scheduling during device charging times
Error Recovery
Troubleshooting
Tasks Not Running
Check Scheduler Status
Performance Considerations
- 60-second check interval provides minute-level precision
- Coroutine-based for lightweight background execution
- Persisted to SharedPreferences for survival across app restarts
- Automatic cleanup when app is destroyed
Lifecycle Management
Next Steps
ClawScript API
Full JavaScript automation reference
Vision Targeting
Use vision AI in scheduled tasks