This post assumes that you have understanding of standard file input/output APIs in java.io.
When working with files in Android, first you need to be aware of Internal and External File storage.
Android devices have two file storage areas: “internal” and “external” storage. During initial days, internal storage means the memory which is built into device, and external storage means external devices such as SD Card which gets mounted to Android device. But these days, even the built in memory has internal and external storage as well. Below are differences between Internal and external Storage
It’s always available.
Files saved here are accessible by only your app by default.
When the user uninstalls your app, the system removes all your app’s files from internal storage.
Internal storage is best when you want to be sure that neither the user nor other apps can access your files.
It’s not always available, because the user can mount the external storage as USB storage and in some cases remove it from the device.
It’s world-readable, so files saved here may be read outside of your control.
When the user uninstalls your app, the system removes your app’s files from here only if you save them in the directory from getExternalFilesDir().
External storage is the best place for files that don’t require access restrictions and for files that you want to share with other apps or allow the user to access with a computer.
Below is an example on how to develop Calculator example on Android platform.
This Application is used to perform arithmetic operations on two integers, which need to be entered in the first two EditText views.
Select the operation you want to perform.
Result is displayed in the last EditText.
Since Android platform can be used to develop apps for various devices with different screen sizes. Various units have been provided to specify sizes like font, width, height,etc… Below is description on the same. px
Pixels – corresponds to actual pixels on the screen. in
Inches – based on the physical size of the screen.
1 Inch = 2.54 centimeters mm
Millimeters – based on the physical size of the screen. pt
Points – 1/72 of an inch based on the physical size of the screen. dp or dip
Density-independent Pixels – an abstract unit that is based on the physical density of the screen. These units are relative to a 160 dpi screen, so one dp is one pixel on a 160 dpi screen. The ratio of dp-to-pixel will change with the screen density, but not necessarily in direct proportion. Note: The compiler accepts both “dip” and “dp”, though “dp” is more consistent with “sp”. sp
Scale-independent Pixels – this is like the dp unit, but it is also scaled by the user’s font size preference. It is recommend you use this unit when specifying font sizes, so they will be adjusted for both the screen density and user’s preference.
Below values are often used with android:layout_width and android:layout_height in XML Layout files
1. fill_parent equivalent integer value is -1. Specifies that view should be as big as its parent (minus padding). This constant is deprecated starting from API Level 8 and is replaced by match_parent.
2. match_parent equivalent integer value is -1. Specifies that view should be as big as its parent (minus padding). Introduced in API Level 8. This has been introduced in API Level 8, to avoid confusion with the term fill_parent, though the behavior is exactly same.
3. wrap_content equivalent integer value is -2. Specifies that view should be only big enough to enclose its content (plus padding).