Alternatives to Activities in Android development?

Android development, Activities alternatives, Android UI components, Fragments, Jetpack Compose, Android navigation
Discover alternatives to Activities in Android development for building responsive and dynamic user interfaces using Fragments and Jetpack Compose.
// Example of using Fragment in Android instead of Activity public class MyFragment extends Fragment { @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // Inflate the layout for this fragment return inflater.inflate(R.layout.fragment_my, container, false); } } // Usage in an Activity public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); // Load the fragment MyFragment myFragment = new MyFragment(); getSupportFragmentManager().beginTransaction() .replace(R.id.fragment_container, myFragment) .commit(); } }

Android development Activities alternatives Android UI components Fragments Jetpack Compose Android navigation