0Pricing
Jetpack Compose Academy · Ders

ViewModel Döndürmeden Neden Sağ Kalır

Yapılandırma değişiklikleri boyunca durumu koruyun.

ViewModel Döndürmeden Neden Sağ Kalır, CoddyKit'te ücretsiz bir Jetpack Compose Academy dersidir. Bu, 4 dersinin 1. dersidir. Aşağıdan dersin tamamını ücretsiz okuyabilir, sonra tarayıcıda yerleşik kod editörü ve 7/24 yapay zeka koçu ile uygulamalı olarak pratik yapabilirsin. Bu, Jetpack Compose Academy öğrenme yolunun bir parçasıdır ve ilerlemeniz web ve CoddyKit uygulaması arasında senkronize olur. Jetpack Compose Academy kursu toplamda 4 dersten oluşur.

Bu dersin bazı bölümleri henüz çevrilmemiş olup İngilizce olarak gösterilmektedir.

The Rotation Problem

Rotate the screen and Android destroys your Activity, wiping any state you stored in it. Your counter, text, and scroll position all vanish. 😵

Configuration Changes

Rotation is one of many configuration changes: theme switches, locale changes, and window resizing all recreate your screen the same way.

Enter the ViewModel

A ViewModel is a class built to hold UI state that outlives the Activity it serves, so a rotation no longer throws your data away.

class CounterViewModel : ViewModel() {
    var count = 0
}

Tied to the Screen, Not the Activity

The ViewModel is scoped to the screen’s lifecycle owner, so the same instance is handed back to the recreated Activity instead of a fresh one.

How It Survives

Android keeps the ViewModel in a retained store across the configuration change, then reconnects it to your brand-new Activity automatically.

When It Is Cleared

A ViewModel lives until the screen is truly finished. When the user navigates away for good, onCleared() runs so you can release resources.

override fun onCleared() {
    // cancel jobs, close streams
}

Not for Everything

The ViewModel survives rotation but not process death. For that, pair it with SavedStateHandle so critical values can be restored later.

Add the Dependency

You get ViewModel support from the lifecycle libraries. Add the lifecycle-viewmodel-compose artifact so Compose can obtain one easily.

implementation("androidx.lifecycle:lifecycle-viewmodel-compose:2.8.0")

Separation of Concerns

Beyond survival, a ViewModel keeps logic out of your UI. Your Composables stay focused on drawing while the ViewModel owns the state.

A Mental Model

Think of the ViewModel as a quiet backstage manager: the Activity comes and goes, but the manager keeps your show’s state ready to perform again.

Why This Matters

Surviving rotation means users never lose progress mid-task. That reliability is the foundation every robust Compose app is built on. ✨

Quick Check

Test your grasp of why a ViewModel outlives a rotation.

Recap

Rotation recreates your Activity, but a ViewModel survives configuration changes and reattaches, keeping UI state intact and logic out of the UI.

Sıkça Sorulan Sorular

“ViewModel Döndürmeden Neden Sağ Kalır” dersi ücretsiz mi?

Evet — “ViewModel Döndürmeden Neden Sağ Kalır” dersin tüm metni burada web'de ücretsiz olarak okunabilir. Etkileşimli olarak pratik yapmak (yerleşik kod editörü ve 7/24 yapay zeka koçu) ve Jetpack Compose Academy kursunun geri kalanını açmak için CoddyKit PRO'ya yükselt. Jetpack Compose Academy kursu toplamda 4 dersten oluşur.

“ViewModel Döndürmeden Neden Sağ Kalır” dersinde ne öğreneceğim?

Yapılandırma değişiklikleri boyunca durumu koruyun. Jetpack Compose Academy ile uygulamalı kodu tarayıcıda doğrudan çalıştırarak pratik yaparsın ve 7/24 yapay zeka koçu dersi çalışırken sorularını yanıtlar.

Jetpack Compose Academy öğrenmeye başlamak için deneyim gerekli mi?

Önceden deneyim gerekmez. CoddyKit'te Jetpack Compose Academy, başlangıçtan ileri seviyeye kadar yapılandırıldığı için buradan başlayabilir veya başından başlayıp kendi hızında ilerleme yapabilirsin. Bu, 4 dersinin 1. dersidir.

“ViewModel Döndürmeden Neden Sağ Kalır” dersi ne kadar sürer?

Çoğu CoddyKit dersi yaklaşık 5–10 dakika sürer. Her biri kısa ve etkileşimli olduğu için sabit ilerleme yaparsın ve web ile uygulama arasında tam olarak bıraktığın yerden devam edebilirsin.

Bu Jetpack Compose Academy dersinde kod yazıp çalıştırabilir miyim?

Evet. Her Jetpack Compose Academy dersi yerleşik bir kod editörü içerir, bu sayede tarayıcıda gerçek kod yazıp çalıştırabilir ve anlık yapay zeka geri bildirimi alırsın — yerel kurulum gerekli değildir.

Bu kursun tüm dersleri

  1. ViewModel Döndürmeden Neden Sağ Kalır
  2. Composable İçinde viewModel()
  3. UiState Veri Sınıfını Modelleme
  4. collectAsStateWithLifecycle
← Jetpack Compose Academy Sayfasına Dön