100% found this document useful (1 vote)
187 views16 pages

Introducere: Programare Pe Platforma Android

This document provides an overview of developing applications on the Android platform. It discusses that Android is based on Linux and designed for mobile touchscreen devices. It also summarizes the key components of an Android application including activities, services, content providers and broadcast receivers. The document outlines the structure of an Android application project and how components are linked together using intents.

Uploaded by

Vitaly Vitaly
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
187 views16 pages

Introducere: Programare Pe Platforma Android

This document provides an overview of developing applications on the Android platform. It discusses that Android is based on Linux and designed for mobile touchscreen devices. It also summarizes the key components of an Android application including activities, services, content providers and broadcast receivers. The document outlines the structure of an Android application project and how components are linked together using intents.

Uploaded by

Vitaly Vitaly
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 16

Introducere

Programare pe platforma
Android
Sistemul de operare Android
● Bazat pe Linux
● Destinat in special dispozitivelor mobile cu
touchscreen
● Android Inc. → Google → Open Handset
Alliance (Google, HTC, Sony, Dell, Intel, Motorola, Samsung, LG, etc.)
● 2008 → Android 5.1 Lollipop (apr, 2015)
● Programare: C, C++, Java
● http://developer.android.com, Android Studio
● “Competitori”: iOS, Windows, Symbian
Aplicatii Java
● Distribuite sub forma: .apk (application package file)
● Java bytecode → Dalvik 'dex-code'
● Executia
– Dalvik virtual machine, JIT
– ART (Android Runtime), ahead-of-time (AOT)
compilation (de la v5.0)
● Aplicatie - Proces Linux - ID unic
● Proces - Masina virtuala - Izolare
● Permisiuni - trebuie acordate de utilizator la
instalarea aplicatiei
Structura unei aplicații
src/
res/
drawable/
layout/
values/
gen/
R.java
AndroidManifest.xml
<manifest ... >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17"/>
</manifest>
Componentele unei aplicații
● Activity: a single screen with a user interface
An email application might have one activity that shows a list of new emails, another
activity to compose an email, and another activity for reading emails
● Service: a component that runs in the
background; does not provide a user interface.
A service might play music in the background while the user is in a different
application, or it might fetch data over the network withoutblocking user interaction.
● Content Provider (file system, SQLite, ...) \\
A content provider manages a shared set of application data. You can store the data
in the file system, an SQLite database, on the web, or any other persistent storage
location your application can access
● Broadcast Receiver: responds to system-wide
broadcast announcements.
For example, a broadcast announcing that the screen has turned off, the battery is
low, or a picture was captured.
Activarea componentelor
● Intent: mesaj asincron ce leaga doua
componente la runtime.
● An intent is an abstract description of an operation to be
performed. It can be used with startActivity to launch an Activity,
broadcastIntent to send it to any interested BroadcastReceiver
components, and startService(Intent) or bindService(Intent,
ServiceConnection, int) to communicate with a background
Service.
● An Intent provides a facility for performing late runtime binding
between the code in different applications. Its most significant
use is in the launching of activities, where it can be thought of
as the glue between activities. It is basically a passive data
structure holding an abstract description of an action to be
performed.
Fisierul manifest
● Componente: <activity>, <service>, <receiver>,
<provider>
● Capabilitatile componentelor:<intent-filter>
● Necesitatile aplicatiei
– Dimensiune ecran: small, normal, large, extra large
– Densitate ecran (dpi): low, medium, high, extra high density
– Modul de interactiune: hardware keyboard, trackball, five-
way navigation pad, etc.
– Facilitați: camera, light sensor, bluetooth, etc.
– Versiunea platformei: minimum API-level
● ...
Hello World
Componente
● MainActivity.java
● DisplayMessageActivity.java
● res/layout/activity_main.xml
● res/layout/activity_display_message.xml
● res/values/strings.xml
● AndroidManifest.xml
● gen/R.java
activity_main.xml
<LinearLayout ...>

<EditText
android:id="@+id/edit_message"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:hint="@string/edit_message" />

<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/button_send"
android:onClick="sendMessage"/>

</LinearLayout>
strings.xml
<resources>

<string name="app_name">HelloWorld</string>

<string name="action_settings">Settings</string>

<string name="hello_world">Hello world!</string>

<string name="edit_message">Enter a message</string>

<string name="button_send">Send</string>

<string name="title_activity_main">MainActivity</string>

<string name="title_activity_display_message">
My Message
</string>

</resources>
MainActivity.java
package com.example.helloworld;
import ...;

public class MainActivity extends Activity {


public final static String EXTRA_MESSAGE =
"com.example.helloword.MESSAGE";

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}

public void sendMessage(View view) {


Intent intent = new Intent(this,DisplayMessageActivity.class);
EditText editText = (EditText)findViewById(R.id.edit_message);
String message = editText.getText().toString();
intent.putExtra(EXTRA_MESSAGE, message);
startActivity(intent);
}
}
activity_display_message.xml
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".DisplayMessageActivity" >

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello_world" />

</RelativeLayout>
DisplayMessageActivity.java
public class DisplayMessageActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

Intent intent = getIntent();


String message =
intent.getStringExtra(MainActivity.EXTRA_MESSAGE);

// Create the text view


TextView textView = new TextView(this);
textView.setTextSize(40);
textView.setText(message);

// Set the text view as the activity layout


setContentView(textView);
}

...
}
R.java
/* AUTO-GENERATED FILE. DO NOT MODIFY.
*
* This class was automatically generated by the
* aapt tool from the resource data it found. It
* should not be modified by hand.
*/
package com.example.helloworld;

public final class R {


public static final class dimen {
public static final int activity_horizontal_margin=0x7f040000;
public static final int activity_vertical_margin=0x7f040001;
}
public static final class id {
public static final int action_settings=0x7f080001;
public static final int edit_message=0x7f080000;
}
...
}
Continuare...
● User Interface
● Resources
● Animation and Graphics (OpenGL)
● Computation (Renderscript)
● Media and Camera
● Location and Sensors
● Connectivity
● Text and Input
● Data Storage
● ...

You might also like