Skip to main content

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

From MainActivity.kt:152-159:
Fields:
  • id: Unique UUID for the task
  • taskDescription: JavaScript code or human-readable description
  • cronExpression: Cron schedule (simplified format)
  • createdAt: Timestamp when task was created
  • lastExecuted: Last execution timestamp
  • isActive: Whether task should run

Scheduler Implementation

PhoneClaw uses Kotlin coroutines for lightweight background scheduling:

Starting the Scheduler

From MainActivity.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

From MainActivity.kt:3521-3555:

Cron Expression Format

PhoneClaw uses a simplified cron format:

Supported Patterns

Expression Parser

From MainActivity.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

From MainActivity.kt:3622-3633:

Via AndroidJSInterface

From MainActivity.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

Rate Limiting: Be mindful of API rate limits and app usage policies. Excessive automation may trigger spam detection on social platforms.
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