# Platform

> Android core components lifecycle, Activities, Fragments, Services, Intent system.

- Skill: `majiayu000/platform-3` (Agent Skill, multi-file: 2 files)
- Install (CLI): `npx skillmds add majiayu000/platform-3`
- Raw SKILL.md: https://api.skillmd.com/api/skills/majiayu000/platform-3/raw
- Safety review: pending
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: Coding & Dev Tools
- Author: majiayu000 (https://skillmd.com/u/majiayu000)
- Updated: 2026-09-09
- Page: https://skillmd.com/skills/majiayu000/platform-3

---


# Android Platform Skill

## Quick Start

### Activity Lifecycle
```kotlin
class MainActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
    }
    
    override fun onDestroy() {
        super.onDestroy()
        // Cleanup
    }
}
```

### Fragment Usage
```kotlin
class UserFragment : Fragment() {
    private val viewModel: UserViewModel by viewModels()
    
    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
        viewModel.user.observe(viewLifecycleOwner) { user ->
            updateUI(user)
        }
    }
}
```

## Key Concepts

### Lifecycle Callbacks
- `onCreate()`: Initial setup
- `onStart()`: Become visible
- `onResume()`: Gain focus
- `onPause()`: Lose focus
- `onStop()`: Hidden
- `onDestroy()`: Final cleanup

### Fragment Lifecycle
Similar to Activity but with:
- `onAttach()`: Attached to activity
- `onDetach()`: Detached
- Fragment manager for transactions

### Intent System
```kotlin
// Explicit
startActivity(Intent(this, DetailActivity::class.java))

// Implicit
startActivity(Intent(Intent.ACTION_VIEW, Uri.parse("https://example.com")))
```

### Services
- Started: `startService()`
- Bound: `bindService()`
- Foreground: Visible notification

## Best Practices

✅ Handle lifecycle properly
✅ Use ViewModel for state
✅ Unregister listeners
✅ Test configuration changes
✅ Respect process lifecycle

## Resources

- [Activity Lifecycle](https://developer.android.com/guide/components/activities)
- [Fragment Guide](https://developer.android.com/guide/fragments)
- [Service Documentation](https://developer.android.com/guide/components/services)

