Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ComponentActivity vs AppCompactActivity in android JetpackCompose

When using the Jetpack Compose, by default it extends the ComponentActivity class. But after trying some samples I switched to AppCompactActivity and everything seemed to work fine. So I wonder what the difference between these is. Do any additional features come with ComponentActivity?

like image 568
Ebin Joy Avatar asked Jun 08 '21 16:06

Ebin Joy


People also ask

Should I use activity or AppCompatActivity?

Unless some third-party library you are using insists upon an ActionBarActivity , you should prefer AppCompatActivity over ActionBarActivity . So, given your minSdkVersion in the 15-16 range: If you want the backported Material Design look, use AppCompatActivity.

What is Android ComponentActivity?

ComponentActivity(@LayoutRes int contentLayoutId) Alternate constructor that can be used to provide a default layout that will be inflated as part of super. onCreate(savedInstanceState) .

What is the use of AppCompatActivity in Android?

Base class for activities that wish to use some of the newer platform features on older Android devices. Some of these backported features include: Using the action bar, including action items, navigation modes and more with the setSupportActionBar(Toolbar) API.

Why jetpack compose is better than XML?

Compose allows you to do more with less code compared to XML. Compose is Intuitive. This means that you just need to tell Compose what you want to show the user. Compose is compatible with all your existing code: you can call Compose code from Views and Views from Compose.

What is the difference between appcompatactivity and componentactivity in Android?

AppCompatActivity extends FragmentActivity which extends ComponentActivity. If you need AppCompat APIs, an AndroidView which works with AppCompat or MaterialComponents theme, or you need Fragment s then use AppCompatActivity. Note: it requires at least the AppCompat 1.3.0 version.

What is Jetpack compose for Android?

Jetpack Compose is a modern toolkit for building native Android UI. Jetpack Compose simplifies and accelerates UI development on Android with less code, powerful tools, and intuitive Kotlin APIs. In this tutorial, you'll build a simple UI component with declarative functions. You won't be editing any XML layouts or using the Layout Editor.

What does appcompatactivity provide to Actionbar?

Based on FragmentActivity, AppCompatActivity provides features to ActionBar What would you use to exit from for each activity and continue the execution of the workflow? In the BPMN standard, you have several artifacts to interrupt an activity and continue the process flow. In my experience the 2 most useful are:

What is the difference between appcompatactivity and fragmentactivity?

Based on Activity, FragmentActivity provides the ability to use Fragment. Based on FragmentActivity, AppCompatActivity provides features to ActionBar What would you use to exit from for each activity and continue the execution of the workflow? In the BPMN standard, you have several artifacts to interrupt an activity and continue the process flow.


1 Answers

AppCompatActivity extends FragmentActivity which extends ComponentActivity.

ComponentActivity has all you need for a Compose-only app.
If you need AppCompat APIs, an AndroidView which works with AppCompat or MaterialComponents theme, or you need Fragments then use AppCompatActivity.

Note: it requires at least the AppCompat 1.3.0 version.

like image 60
Gabriele Mariotti Avatar answered Oct 16 '22 16:10

Gabriele Mariotti