Basicofandroid 141112104211 Conversion Gate02
Basicofandroid 141112104211 Conversion Gate02
Basicofandroid 141112104211 Conversion Gate02
ANDROID
1. Introduction to Mobile Technologies
2. Introduction of Android
6. Android Activities
7. UI Design
9. Database - SQLite
10. Broadcast
1. INTRODUCTION TO
MOBILE TECHNOLOGY
INTRODUCTION TO MOBILE
TECHNOLOGIES
Android Java
• Many APIs are similars but you don't have all J2SE APIs.
• No Swing, no JavaFX ... You must use XML to declare you GUI;
• you can use java jars (if they use only compatible APIs) but they are
converted into dalvik.
3.1 Activity
3.2 Broadcast Receiver
3.3 Content Provider
3.4 Service
3.5 Introduction of Intent
3. ANDROID BUILDING BLOCKS
Activities
Services
Content providers
Broadcast receivers
3.1 ACTIVITY
• http://developer.android.com/sdk/index.html
ANDROID DEVELOPMENT TOOLS
Android Manifest
52
4.4 FIRST PROJECT “HELLO WORLD”
Inherit
package com.example.helloandroid; from the
Activity
import android.app.Activity;
import android.os.Bundle; Class
import android.widget.TextView;
public class HelloAndroid extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
TextView tv = new TextView(this);
tv.setText("Hello, Android – by hand");
setContentView(tv);
}
}
Set the view “by
hand” – from the
program
53
RUN IT!
54
/RES/LAYOUT/MAIN.XML
55
/RES/VALUES/STRINGS.XML
56
HELLOANDROID.JAVA
package com.example.helloandroid;
import android.app.Activity;
import android.os.Bundle;
public class HelloAndroid extends Activity {
package com.example.helloandroid;
public final class R {
public static final class attr {
}
public static final class drawable {
public static final int icon=0x7f020000;
}
public static final class id {
public static final int textview=0x7f050000;
}
public static final class layout {
public static final int main=0x7f030000;
}
public static final class string {
public static final int app_name=0x7f040001;
public static final int hello=0x7f040000;
}
}
58
RUN IT!
59
5. TESTING AND DEBUGGING
ANDROID APPLICATION
5. TESTING AND DEBUGGING ANDROID
APPLICATION
71
6.1 ANDROID ACTIVITY LIFECYCLE
AN ACTIVITY : THREE STATES
73
AN ACTIVITY : THREE STATES (CONTD.)
75
6.2 USING INTENT TO LAUNCH THE
ACTIVITIES
• Intent are asynchronous messages which allow the
application to request functionality from other Android
components, e.g. from services or activities
• Frame Layout
• Liner Layout
• Relative Layout
• Table Layout
FRAMELAYOUT
99
CHECK BOX
100
RADIO BUTTONS
101
SCROLLVIEW
103
EVENT DRIVEN PROGRAMMING IN
ANDROID
There is a simple truth:
106
OPTIONS MENU AND ACTION BAR
107
CONTEXT MENU AND CONTEXTUAL
ACTION MODE
109
CREATING CONTEXTUAL MENUS
113
DIALOG
114
CREATE AN ALERT DIALOG?
Creating alert dialog is very easy :
// Setting OK Button
alertDialog.setButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
// Write your code here to execute after dialog closed
Toast.makeText(getApplicationContext(), "You clicked on OK", Toast.LENGTH_SHORT).show();
}
});
Sample Code :
• If you call one of the notify methods with a (tag, id) pair
that is currently active and a new set of notification
parameters, it will be updated
8.6 PENDING INTENT
126
• A notification in normal view appears in an area that's
up to 64 dp tall. Even if you create a notification with a
big view style, it will appear in normal view until it's
expanded. This is an example of a normal view:
The callouts in the illustration refer to the following:
1. Content title
2. Large icon
3. Content text
4. Content info
5. Small icon
6. Time that the notification was issued. You can set an
explicit value with setWhen(); if you don't it defaults to
the time that the system received the notification. 127
9. USING ANDROID
SYSTEM SERVICES
9. SERVICE INTRO
129
SERVICE INTRO(CONTD.)
130
RUNNING A SERVICES IN ITS OWN
PROCESS
• You can also specify that your Service runs in a
separate process via the
android:process =":process_description" attribute.
• This way the service gets its own process and has its
own memory. Any long running operation in
theService, e.g. a garbage collection, will not affect
the user interface of your Activity.
• The colon prefix before the name tells Android that
the Service is private to its declaring application. If
the colon is not used the Service would be a global
process and can be used by other components.
131
• <service
android:name="WordService"
android:process=":my_process"
android:icon="@drawable/icon"
android:label="@string/service_name" >
</service>
• The colon prefix before the name tells Android that
the Service is private to its declaring application. If
the colon is not used the Service would be a global
process and can be used by other components.
• Additionally, you can ensure that your service is
private to your application only if you include
theandroid:exported attribute and set it to "false".
132
FORMS OF SERVICE
134
SERVICE LIFECYCLE
rawQuery() Example
The following gives an example of a rawQuery() call.
• Cursor cursor =
getReadableDatabase().rawQuery("select * from
todo where _id = ?", new String[] { id });
QUERY()
query() Example
The following gives an example of a query() call.
• return database.query(DATABASE_TABLE,
new String[] { KEY_ROWID, KEY_CATEGORY,
KEY_SUMMARY, KEY_DESCRIPTION }, null, null, null,
null, null);
10.3 OPENING AND CLOSING A
DATABASE
SQLiteDatabase db = this.getWritableDatabase();
//Opening DatabaseConnection
// Inserting Row
db.insert(TABLE_CONTACTS, null, values);
db.close(); // Closing database connection
WORKING WITH CURSORS INSERTS,
UPDATES, AND DELETES
Cursor
• A query returns a Cursor object. A Cursor represents the
result of a query and basically points to one row of the
query result. This way Android can buffer the query
results efficiently; as it does not have to load all data into
memory.
database.delete(MySQLiteHelper.TABLE_COMMENTS,
MySQLiteHelper.COLUMN_ID + " = " + id, null);
CONTENT PROVIDER AND SHARING
DATA
• A SQLite database is private to the application which
creates it. If you want to share data with other
applications you can use a content provider.