Android Architecture & Implementation
Guide
A Deep Dive into Android Development
By Hemant Kumar Singh
Connect with me: linkedin.com/in/hemant-kumar-singh11
August 2025
Contents
1 Introduction to Android Architecture 2
2 Android Components 2
2.1 Activity Lifecycle . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
3 Internal Implementation: ViewModel and LiveData 2
3.1 ViewModel . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
3.2 LiveData . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
4 Practical Example: Building a Counter App 3
5 Conclusion 4
1
1 Introduction to Android Architecture
Android’s architecture is built to ensure modularity, scalability, and performance. At its core,
Android apps are structured around key components that interact seamlessly with the operating
system. This guide explores these components and provides practical examples to solidify your
understanding.
2 Android Components
Android apps are built using four primary components: Activities, Services, Broadcast Re-
ceivers, and Content Providers. Each plays a unique role in app functionality.
Key Components
• Activity: Represents a single screen with a user interface.
• Service: Runs background tasks without a UI.
• Broadcast Receiver: Listens for system-wide events.
• Content Provider: Manages shared app data.
2.1 Activity Lifecycle
The Activity lifecycle is critical for managing UI states. It includes states like onCreate(),
onStart(), onResume(), onPause(), onStop(), onDestroy(), and onRestart().
Activity Lifecycle Example
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Log.d("Lifecycle", "onCreate called");
}
@Override
protected void onStart() {
super.onStart();
Log.d("Lifecycle", "onStart called");
}
}
3 Internal Implementation: ViewModel and LiveData
Modern Android development leverages architecture components like ViewModel and LiveData
to build robust, lifecycle-aware apps.
3.1 ViewModel
ViewModel stores and manages UI-related data, surviving configuration changes like screen
rotations.
2
ViewModel Example
public class MyViewModel extends ViewModel {
private MutableLiveData<String> data = new MutableLiveData<>();
public void setData(String value) {
data.setValue(value);
}
public LiveData<String> getData() {
return data;
}
}
3.2 LiveData
LiveData is an observable data holder that respects the lifecycle of app components.
LiveData in Activity
public class MainActivity extends AppCompatActivity {
private MyViewModel viewModel;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
viewModel = new ViewModelProvider(this).get(MyViewModel.class);
viewModel.getData().observe(this, data -> {
Toast.makeText(this, data, Toast.LENGTH_SHORT).show();
});
}
}
4 Practical Example: Building a Counter App
Let’s implement a simple counter app using ViewModel and LiveData to demonstrate real-world
application.
Counter App XML Layout
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:id="@+id/counterText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="0" />
<Button
android:id="@+id/incrementButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
3
android:text="Increment" />
</LinearLayout>
Counter App Activity
public class CounterActivity extends AppCompatActivity {
private CounterViewModel viewModel;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_counter);
viewModel = new ViewModelProvider(this).get(CounterViewModel.class);
TextView counterText = findViewById(R.id.counterText);
Button incrementButton = findViewById(R.id.incrementButton);
viewModel.getCount().observe(this, count -> {
counterText.setText(String.valueOf(count));
});
incrementButton.setOnClickListener(v -> viewModel.increment());
}
}
Counter ViewModel
public class CounterViewModel extends ViewModel {
private MutableLiveData<Integer> count = new MutableLiveData<>(0);
public LiveData<Integer> getCount() {
return count;
}
public void increment() {
count.setValue(count.getValue() + 1);
}
}
5 Conclusion
Understanding Android’s architecture and leveraging components like ViewModel and LiveData
can significantly enhance app quality. Experiment with the counter app example and explore
further to master Android development!
Learn more and connect: linkedin.com/in/hemant-kumar-singh11