Optimization | Effect |
---|---|
Combination of multiple Class files in one DEX file | Smaller memory footprint, faster load of the application |
Sharing of DEX files between processes (read-only mapping) | Smaller memory footprint, faster load of the application |
Byte ordering and word alignment according to local machine (install time) | Faster load of the application DEX file itself still platform independent |
Bytecode pre-verification (as much as possible, install time) | Faster load and execution |
Install-time optimization of bytecode | Faster execution, still platform independence |
Register instead of stack based virtual machine | Faster execution (~30%) |
/Users/\<user>/Library/Android/sdk/platform-tools
> adb -e shell
> adb push \<local> \<remote>
> adb pull \<remote> \[\<local>]
> adb install \<file>
<?xml version="1.0" encoding="utf-8"?>
<manifest>
<uses-permission />
<application>
<activity>
<intent-filter>
<action />
<category />
<data />
</intent-filter>
<meta-data />
</activity>
<service>
<intent-filter> ... </intent-filter>
<meta-data/>
</service>
</application>
</manifest>
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView" />
</androidx.constraintlayout.widget.ConstraintLayout>
ViewGroup
and View
objectsView
s are for example TextView
, Button
, etc.ConstraintLayout
, LinearLayout
, RelativeLayout
, RecyclerView
, etc.ViewGroup
s can contain View
s and other ViewGroup
sDesign Pattern Hint: Composite
public class MainActivity extends AppCompatActivity {
// ...
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main_layout);
// ...
}
// ...
}
View
and ViewGroup
object supports own attributes<Button
android:id="@+id/my_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/my_button_text"/>
android:id
allows to identify the component from Java code after layout initialization:Button myButton = (Button) findViewById(R.id.my_button);
Note: findViewById
is an expensive operation and should be used with care. Modern ways optimize
the usage of findViewById
and provide alternative ways to reference elements in layouts via
data binding and
view binding.
Layout parameters define positioning and size of the component when rendered
ViewGroup
class implements nested class that extends ViewGroup.LayoutParams
that define the
size and position for each child view
wrap_content
tells your view to size itself to the dimensions required by its content
match_parent
tells your view to become as big as its parent view group will allow
A ConstraintLayout
is a android.view.ViewGroup
which allows you to position and size widgets in
a flexible way.
A layout that organizes its children into a single horizontal or vertical row. It creates a scrollbar if the length of the window exceeds the length of the screen.
Enables you to specify the location of child objects relative to each other (child A to the left of child B) or to the parent (aligned to the top of the parent).
@string
) and images
(@drawable
):<Button
android:id="@+id/button"
android:layout_width="113dp"
android:layout_height="101dp"
android:background="@drawable/ic_input_add"
android:text="@string/button_text" />
/res/values/strings.xml
/res/drawable
/res/mipmap
/res/layout
Create a new directory in res/ named in the form <resources_name>-<config_qualifier>
<resources_name>
is the directory name of the corresponding default resources<qualifier>
is a name that specifies an individual configuration for which these resources
are to be usedSave the respective alternative resources in this new directory. The resource files must be named exactly the same as the default resource files
res/
drawable/
icon.png
background.png
drawable-hdpi/
icon.png
background.png
Sizes of view components should be defined in Density Independent Pixels (dp) in order to always get the best results.
More information here.
dp
) describes the size of a UI element in a density independent
manner 160ppi
, one dp corresponds to one physical pixel (px)160ppi
, the dp values are converted with the help of the
densityFactor
densityFactor
describes the device's physical density in relation to the default density of
160ppi
densityFactor
at runtime:float densityFactor = getResources().getDisplayMetrics().density;
R.java
filepublic final class R {
// ...
public static final class layout {
public static final int activity_main = 0x7f030000;
}
public static final class mipmap {
public static final int ic_launcher = 0x7f020000;
public static final int ic_launcher_round = 0x7f020001;
}
public static final class string {
public static final int ButtonText = 0x7f050000;
public static final int app_name = 0x7f050001;
}
}
android:id
is
added to it<Button
android:id="@+id/button"
... />
Note: AndroidX is the successor of the deprecated Android Support Libraries. The usage of the old Android Support Libraries is not recommended anymore for most of the projects.
AppCompatActivity
class is the default class used for Activities that want to make
use of the new Material Design features (introduced with API level 21)
build.gradle
/build.gradle.kts
filesThis blank slide is dedicated to Kotlin, which has become the de facto programming language for Android app development.