Download Introducere Programare pe platforma Android

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts
no text concepts found
Transcript
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, fiveway 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
public static final int
public static final int
}
public static final class
public static final int
public static final int
}
...
}
dimen {
activity_horizontal_margin=0x7f040000;
activity_vertical_margin=0x7f040001;
id {
action_settings=0x7f080001;
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
...
Related documents