Anda di halaman 1dari 18

Android

Introduction
FOR SOFTWARE DEVELOPMENT FOR PORTABLE DEVICES
2016
BY AYUSH KUMAR

Introduction
Written in Java programming language
Android SDK tools compile your codealong with any data
and resource filesinto an APK: an Android package, which is
an archive file with an .apk suffix.
The Dalvik VM enables every Android application to run in its
own process, with its own instance of the Dalvik virtual
machine.

Application components
Application components are the essential building
blocks of an Android application
AndroidManifest.xml describes each component of the
application and how they interact.
Activities, Services, Broadcast Receivers, Content
Providers are the 4 application components

Activities
An activity represents a single screen with a user interface
Represented in Android Manifest as,
<manifest ... >
<application ... >
<activity android:name=".ExampleActivity" />
...
</application ... >
...
</manifest >

Launcher Activity
<activity android:name=".ExampleActivity"
android:icon="@drawable/app_icon">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category
android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

Starting an Activity
Intent intent = new Intent(this, MyNewAcitivity.class);
startActivity(intent);

Intents are used to launch application components like Activities, Services.

onCreate()
Called when the activity is first created. This is where you should do all
of your normal static set up create views, bind data to lists, and so on.
Always followed by onStart().
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// The activity is being created.
}

onStart()
Called just before the activity becomes visible to the user.
Followed by onResume() if the activity comes to the foreground, or
onStop() if it becomes hidden.
@Override
protected void onStart() {
super.onStart();
// The activity is about to become visible.
}

onResume()
Called just before the activity starts interacting with the user.
At this point the activity is at the top of the activity stack, with
user input going to it.
Always followed by onPause().
@Override
protected void onResume() {
super.onResume();
// The activity has become visible (it is now "resumed").
}

onPause()
Called when the system is about to start resuming another activity. This
method is typically used to commit unsaved changes to persistent data, stop
animations and other things that may be consuming CPU, and so on
Followed either by onResume() if the activity returns back to the front, or by
onStop() if it becomes invisible to the user.
protected void onPause() {
super.onPause();
// Another activity is taking focus (this activity is about to be
"paused").
}

onStop()
Called when the activity is no longer visible to the user. This may happen
because it is being destroyed, or because another activity (either an
existing one or a new one) has been resumed and is covering it.
Followed either by onRestart() if the activity is coming back to interact
with the user, or by onDestroy() if this activity is going away.
protected void onStop() {
super.onStop();
// The activity is no longer visible (it is now "stopped")
}

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); // Always call the superclass first

// Check whether we're recreating a previously destroyed instance


if (savedInstanceState != null) {
// Restore value of members from saved state
mCurrentScore = savedInstanceState.getInt(STATE_SCORE);
mCurrentLevel = savedInstanceState.getInt(STATE_LEVEL);
} else {
// Probably initialize members with default values for a new instance
}
...
}

UI
Declare UI elements in XML. Android provides a
straightforward XML vocabulary that corresponds to the View
classes and subclasses, such as those for widgets and layouts.
Instantiate layout elements at runtime. Your application
can create View and ViewGroup objects (and manipulate their
properties) programmatically.
setContentView(R.layout.main_layout);

Layouts
LinearLayout is a view group that aligns all children in a single
direction, vertically or horizontally. You can specify the layout
direction with the android:orientation attribute.
RelativeLayout is a view group that displays child views in
relative positions. The position of each view can be specified as
relative to sibling elements (such as to the left-of or below
another view) or in positions relative to the parent RelativeLayout
area (such as aligned to the bottom, left or center).

Thank
you.

Anda mungkin juga menyukai