Image source: giphy.com
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"?>
<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/text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello, I am a TextView" />
<Button android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello, I am a Button" />
</LinearLayout>
Design Pattern Hint: Composite
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main_layout);
}
<Button android:id="@+id/my_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/my_button_text"/>
Button myButton = (Button) findViewById(R.id.my_button);
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).
<Button
android:id="@+id/button"
android:layout_width="113dp"
android:layout_height="101dp"
android:background="@android:drawable/ic_input_add"
android:text="@string/ButtonText" />
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
float densityFactor = getResources().getDisplayMetrics().density;
public 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;
}
<Button
android:id="@+id/button"
...
/>