android-networking-retrofit-okhttp

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Android Networking Retrofit OkHttp

Android网络开发:Retrofit与OkHttp

When To Use

适用场景

  • Use this skill when the request is about: retrofit android setup, okhttp interceptor android, api error mapping android.
  • Primary outcome: Build Android networking stacks with Retrofit, OkHttp, interceptors, API contracts, and resilient error handling.
  • Handoff skills when the scope expands:
  • android-serialization-offline-sync
  • android-security-best-practices
  • 当请求涉及以下内容时使用本技能:Android Retrofit配置、Android OkHttp拦截器、Android API错误映射。
  • 核心目标:使用Retrofit、OkHttp、拦截器、API契约和弹性错误处理构建Android网络栈。
  • 当范围扩大时移交至以下技能:
  • android-serialization-offline-sync
  • android-security-best-practices

Workflow

工作流程

  1. Confirm the data source, persistence boundary, sync model, and device capability involved.
  2. Model contracts explicitly before wiring network, storage, media, or background APIs.
  3. Apply the recommended AndroidX or platform pattern with migration-safe defaults.
  4. Validate offline, retry, and process death behavior against the sample apps and scenarios.
  5. Escalate security, performance, or release risk to the linked supporting skills when needed.
  1. 确认涉及的数据源、持久化边界、同步模型和设备能力。
  2. 在连接网络、存储、媒体或后台API之前,显式建模契约。
  3. 采用推荐的AndroidX或平台模式,使用具备迁移安全性的默认配置。
  4. 对照示例应用和场景验证离线、重试和进程销毁行为。
  5. 必要时将安全、性能或发布风险上报至关联的支持技能。

Guardrails

防护准则

  • Prefer typed models and explicit serializers over ad-hoc maps or bundles.
  • Keep background work idempotent and cancellation-aware.
  • Do not leak storage, media, or networking details into presentation code.
  • Treat user data durability, privacy, and migration paths as part of the implementation.
  • 优先使用类型化模型和显式序列化器,而非临时的map或bundle。
  • 确保后台工作具备幂等性和取消感知能力。
  • 不要将存储、媒体或网络细节泄露到展示层代码中。
  • 将用户数据持久性、隐私和迁移路径视为实现的一部分。

Anti-Patterns

反模式

  • Blocking the main thread with disk or network calls.
  • Treating retryable sync failures as terminal user-facing errors.
  • Mixing cache models and wire models without a mapping layer.
  • Requesting broad storage or notification capabilities when a narrower API exists.
  • 磁盘或网络调用阻塞主线程。
  • 将可重试的同步失败视为面向用户的最终错误。
  • 没有映射层的情况下混用缓存模型和传输模型。
  • 存在更窄范围的API时,仍请求宽泛的存储或通知权限。

Examples

示例

Happy path

正常路径

  • Scenario: Model sync requests and network failures for task refresh.
  • Command:
    cd examples/orbittasks-compose && ./gradlew :app:testDebugUnitTest
  • 场景:为任务刷新功能建模同步请求和网络失败处理。
  • 命令:
    cd examples/orbittasks-compose && ./gradlew :app:testDebugUnitTest

Edge case

边缘场景

  • Scenario: Handle stale cache and retry behavior in the XML fixture.
  • Command:
    cd examples/orbittasks-xml && ./gradlew :app:testDebugUnitTest
  • 场景:在XML fixture中处理过期缓存和重试行为。
  • 命令:
    cd examples/orbittasks-xml && ./gradlew :app:testDebugUnitTest

Failure recovery

故障恢复

  • Scenario: Differentiate networking prompts from serialization, security, and offline-sync requests.
  • Command:
    python3 scripts/eval_triggers.py --skill android-networking-retrofit-okhttp
  • 场景:区分网络提示与序列化、安全和离线同步请求。
  • 命令:
    python3 scripts/eval_triggers.py --skill android-networking-retrofit-okhttp

Done Checklist

完成 Checklist

  • The implementation path is explicit, minimal, and tied to the right Android surface.
  • Relevant example commands and benchmark prompts have been exercised or updated.
  • Handoffs to adjacent skills are documented when the request crosses boundaries.
  • Official references cover the chosen pattern and the main migration or troubleshooting path.
  • 实现路径明确、精简,且与对应的Android能力绑定。
  • 相关的示例命令和基准提示已测试或更新。
  • 当请求跨领域时,已记录向相邻技能的移交方式。
  • 官方参考资料覆盖了所选模式及主要迁移或故障排查路径。

Official References

官方参考