Your SlideShare is downloading. ×
02   hello world - Android
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×

Introducing the official SlideShare app

Stunning, full-screen experience for iPhone and Android

Text the download link to your phone

Standard text messaging rates apply

02 hello world - Android

491
views

Published on

Basic methods of implementing a hello w

Basic methods of implementing a hello w

Published in: Education, Technology

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
491
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
30
Comments
0
Likes
0
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. Workshop India
  • 2. » Android applications are written in the Java programming language.» The Android SDK tools perform compilation of the code into Android package (an archive file - .apk)» Android applications do not run directly as linux binaries, they are actually sandboxed within the Dalvik Virtual Machine.
  • 3. » Each application is a different *user* within the android OS.» The system assigns a UID for every app, so that the app can only access data/resources assigned to it.» Each process executes in a VM that compeletely isolates apps from each other.» The Android OS performs the starting / stopping / pausing / interrupting of all applications within itself.
  • 4. » Activities ˃ An activity represents a single screen with a user interface.» Services ˃ A service is a UI-less component that runs in the background to perform long- running operations or to perform work for remote processes.» Content providers ˃ A content provider manages a shared set of application data. ˃ Which may be in the file system, an SQLite database, on the web, or any other persistent storage location your application can access.» Broadcast receivers ˃ A broadcast receiver is a component that responds to system-wide broadcast announcements. ˃ Eg: a broadcast announcing that the screen has turned off, ˃ Or : the battery is low
  • 5. » To begin programming with Android in Eclipse, select File > New > Project… to display the New Project dialog.
  • 6. » It is a required component of all applications and must be present in the root of the source code .» Identify any user permissions the application requires, such as Internet access or read-access to the users contacts.» Has the API level the application required from the device which controls if the app is installed or not installed on various devices.» Declare hardware and software features used or required by the application, such as a camera, bluetooth services, or a multitouch screen.
  • 7. package com.learnandroid.helloworld;import android.app.Activity;import android.os.Bundle;import android.widget.TextView;public class Hello extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); TextView helloText = new TextView(this); helloText.setText("Hello World"); setContentView(helloText); This creates a TextView, sets } the text and sets it to display} in the current context
  • 8. » Android Development allows for seperation of UI design layouts (.xml) and application logic (java classes)» Layouts are defined in the /res/layouts folder.» In the implementation class setContentView() is called with a reference to the layout xml file to render it to the screen.
  • 9. 1. xml schema defines a texview with id label 2. This file is called main.xmlpackage com.learnandroid.hellowworld; 3. In java code, you can find thatimport android.app.Activity; view and perform a setText() on itimport android.os.Bundle; to get the text in it..import android.widget.TextView;public class Hello2 extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); TextView label = (TextView) findViewById(R.id.label); label.setText("Hello World"); }}
  • 10. » Toasts are popup notifications that appear and disappear without any user interaction required. package com.learnandroid.helloworld; import android.app.Activity; import android.os.Bundle; import android.view.Gravity; import android.widget.Toast; public class Hello3 extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); Toast helloToast = Toast.makeText(this, "Hello World", Toast.LENGTH_LONG); helloToast.setGravity(Gravity.CENTER, 0, 0); helloToast.show(); } }
  • 11. package com.learnandroid.helloworld;import android.app.Activity; These imports handle the textimport android.os.Bundle;import android.speech.tts.TextToSpeech; to speech converterimport android.speech.tts.TextToSpeech.OnInitListener;public class Hello4 extends Activity implements OnInitListener The implements oninitListener allows{ private TextToSpeech tts; you to use the interface that informs static final int TTS_CHECK_CODE = 0; you when the phone’s text to speech engine has started. /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); A new instant of tts is tts = new TextToSpeech(this, this); } created, note that tts is a private class variable.@Override public void onInit(int initStatus) { if (initStatus == TextToSpeech.SUCCESS) { tts.speak("Hello World", TextToSpeech.QUEUE_FLUSH, null); } }} This function is called on init and performs the actual speaking..