Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Introduction to Android

Introduction to Android

Nicolas Magni

June 25, 2013
Tweet

Other Decks in Programming

Transcript

  1. <?xml version="1.0" encoding="utf-8"?> <manifest ... > <application android:icon="@drawable/app_icon.png" ... >

    <activity android:name="com.example.project.ExampleActivity" android:label="@string/example_label" ... > </activity> ... </application> </manifest> Android Manifest Permissions API Level Components API libraries Software Features Declare Hardware Declaring component capabilities Tuesday, June 25, 13
  2. Intent intent = new Intent(this, SignInActivity.class); startActivity(intent); Intent intent =

    new Intent(Intent.ACTION_SEND); intent.putExtra(Intent.EXTRA_EMAIL, recipientArray); startActivity(intent); private void pickContact() { Intent intent = new Intent(Intent.ACTION_PICK, Contacts.CONTENT_URI); startActivityForResult(intent, PICK_CONTACT_REQUEST); } @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (resultCode == Activity.RESULT_OK && requestCode == PICK_CONTACT_REQUEST) { // Perform a query to the contact's content provider for the contact's name ... } } Activities Tuesday, June 25, 13
  3. An activity can exist in essentially three states Resumed Stopped

    Paused The entire lifetime of an activity happens between the call to onCreate() and the call to onDestroy() The visible lifetime of an activity happens between the call to onStart() and the call to onStop(). The foreground lifetime of an activity happens between the call to onResume() and the call to onPause(). Activities life cycle Tuesday, June 25, 13
  4. Services Broadcast receivers ★Getting data form the server. ★Posting data.

    ★Streaming audio or video. ★SQL insert(Intent service.) ★Screen has turned off. ★The battery is low. ★Picture was captured. ★Initiate a service to perform some work based on the event. Tuesday, June 25, 13
  5. Content providers Calendar Provider User Provider Content providers manage access

    to a structured set of data. Decide if you need a content provider. • You want to offer complex data or files to other applications. • You want to allow users to copy complex data from your app into other apps. • You want to provide custom search suggestions using the search framework. Tuesday, June 25, 13
  6. Layouts <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/ android" android:layout_width="fill_parent" android:layout_height="fill_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> Tuesday, June 25, 13
  7. <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http:// schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:paddingLeft="16dp" android:paddingRight="16dp"

    android:orientation="vertical" > <EditText android:layout_width="fill_parent" android:layout_height="wrap_content" android:hint="@string/to" /> <EditText android:layout_width="fill_parent" android:layout_height="wrap_content" android:hint="@string/subject" /> <EditText android:layout_width="fill_parent" android:layout_height="0dp" android:layout_weight="1" android:gravity="top" android:hint="@string/message" /> <Button android:layout_width="100dp" android:layout_height="wrap_content" android:layout_gravity="right" android:text="@string/send" /> </LinearLayout> Linear Layouts Tuesday, June 25, 13
  8. <EditText android:id="@+id/name" android:layout_width="fill_parent" android:layout_height="wrap_content" android:hint="@string/reminder" /> <Spinner android:id="@+id/dates" android:layout_width="0dp" android:layout_height="wrap_content"

    android:layout_below="@id/name" android:layout_alignParentLeft="true" android:layout_toLeftOf="@+id/times" /> <Spinner android:id="@id/times" android:layout_width="96dp" android:layout_height="wrap_content" android:layout_below="@id/name" android:layout_alignParentRight="true" /> <Button android:layout_width="96dp" android:layout_height="wrap_content" android:layout_below="@id/times" android:layout_alignParentRight="true" android:text="@string/done" /> Relative Layouts Tuesday, June 25, 13
  9. Input control Easy customization <?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item

    android:drawable="@drawable/button_pressed" android:state_pressed="true" /> <item android:drawable="@drawable/button_focused" android:state_focused="true" /> <item android:drawable="@drawable/button_default" /> </selector> Define custom styles. If you can use defined values. Tuesday, June 25, 13
  10. private Button mSubmitButton; UI widgets final String USERNAME; Settings and

    intent strings final String BASEURL; final String TAG; Layout Names activityLogin fragmentLogin adapterUser One folder for each components type. Guidelines PlayStore Keys on the repo! Tuesday, June 25, 13
  11. static class ViewHolder { TextView text; TextView timestamp; ImageView icon;

    ProgressBar progress; int position; } ViewHolder holder = new ViewHolder(); holder.icon = (ImageView) convertView.findViewById(R.id.listitem_image); holder.text = (TextView) convertView.findViewById(R.id.listitem_text); holder.timestamp = (TextView) convertView.findViewById(R.id.listitem_timestamp); holder.progress = (ProgressBar) convertView.findViewById(R.id.progress_spinner); convertView.setTag(holder); Hold View Objects in a View Holder Use a Background Thread Performance Tuesday, June 25, 13
  12. Performance ★Avoid Creating Unnecessary Objects ★Prefer Static Over Virtual ★Use

    Static Final For Constants ★Avoid Internal Getters/Setters ★Use Enhanced For Loop Syntax ★Use AsyncTasks ! Tuesday, June 25, 13
  13. Google Services Location APIs ★Activity recognition ★Geofencing APIs ★Fused location

    provider Google Cloud Messaging for Android ★Send data from your server to users' Android-powered devices. Google+ Platform for Android ★Google+ Sign-In Google Play Distribution ★ Production, Beta Testing, Alpha Testing New Stuff Tuesday, June 25, 13