1 / 28

All About Android

All About Android. Introduction to Android. Creating a New App. “These aren’t the droids we’re looking for.” Obi-wan Kenobi 1. Bring up Eclipse. 2. Click on File->New->Android Application Project

Télécharger la présentation

All About Android

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.


Presentation Transcript

  1. All About Android Introduction to Android Introduction to Android

  2. Creating a New App • “These aren’t the droids we’re looking for.” Obi-wan Kenobi 1. Bring up Eclipse. 2. Click on File->New->Android Application Project 3. Enter an application name, such as HelloWorld. This is how your app will show on your device. Introduction to Android

  3. Creating a New App (continued) 4. The Project Name and Package name will default. No reason to change them. 5. On the next page, you can leave everything as defaults unless you want your projects in a specific location. 6. You can change the icon or use the defaults. 7. On the next screen, choose Blank Activity Introduction to Android

  4. Creating a New App (continued) 8. On the final screen, change the name of the activity to something about your project, such as HelloWorldActivity. 9. Click Finish and you’re done. Introduction to Android

  5. What Just Happened • You should now have a .java file with the name of your activity as a class name and file name that extends Activity • Your file will have an OnCreate method, which is equivalent to calling the “main” method in a standard Java program. This is the constructor of your application. Introduction to Android

  6. Running The App • Configure your device for USB Debugging (this is different for every device) • Connect your Android device to your computer with the USB cable • Do not select anything when Windows pops up and asks how to connect, or (strangely), set it up as a camera. Introduction to Android

  7. Running The App • Right-click on the project name on the left and select Run As->Android Application from the context menu • Eclipse should now have downloaded the app to your device and started it. If you have done this correctly, the app is running. Introduction to Android

  8. Running the App • You should get a screen that looks like this: User Interface Design -- Android Part 1

  9. Running the App • If your device is connected properly, it will show in the top box. You see my Samsung Galaxy S3 phone. • You can also run in the emulator, which is slow and doesn’t provide the same interface. User Interface Design -- Android Part 1

  10. What You Have • activity_main.xml is the screen design for your app. Like Swing, it has a layout manager • The TextView contains a reference to a string in the resource file: <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/hello_world" /> User Interface Design -- Android Part 1

  11. What You Have • Under res\values you have a file called strings.xml • Clicking on one of the string designators shows you its value and allows you to change it User Interface Design -- Android Part 1

  12. The Program • You have a main class, but no main method. Your class is: publicclassMainActivityextends Activity So in Android, every screen is an activity User Interface Design -- Android Part 1

  13. The Program • The Activity class contains various methods. This example overrides the OnCreate message: @Override protectedvoidonCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); } User Interface Design -- Android Part 1

  14. The Application Manifest • Every Android project includes a manifest file, AndroidManifest.xml, stored in the root of its project file. • This defines the structure and metadata for your app, its components, and hardware and other requirements. Introduction to Android

  15. Other Useful Overrides • onPause – called when the activity is paused • onResume – called when the activity becomes visible (active) again • onStop – called before the activity stops • This may look somewhat familiar if you have written java applets User Interface Design -- Android Part 1

  16. What Makes an Android App? • Activities – These are the presentation layer for your app. You create extensions to this class for your different UI components. • Services – These run without a UI, updating data sources and activities, etc. • Content Providers – Shareable persistent storage such as the SQLite database Introduction to Android

  17. What Makes an Android App? • Intents – A powerful interapplication message-passing framework. You can use them to start and stop services and pass information to different activities. • Broadcast Receivers – Intent listeners. (Subscribers, in the publish-subscribe design pattern) Introduction to Android

  18. What Makes an Android App? • Widgets – Visual application components that are typically added to the device home screen. • Notifications – These enable you to alert users to application events without stealing focus or interrupting their current Activity. Introduction to Android

  19. The Android Application Lifecycle • Android apps have limited control over their lifecycle • Android manages resources to ensure a smooth and stable user experience Introduction to Android

  20. Android Processes • Active processes – foreground processes with which the user is interacting. These are killed only as a last resort • Visible processes – these are inactive processes hosting visible Activities that are not in the foreground Introduction to Android

  21. Android Processes • Started Service processes – Hosting Services that have started. Since they don’t interact with the user, they have slightly lower priority. • Background Processes – These host Activities that aren’t visible and have no running Services. • Empty Processes – Android will often retain an application in memory after it ends. Introduction to Android

  22. The Android Application Class • Your app’s Application object remains instantiated whenever your app runs. Application is not restarted as a result of configuration changes. Introduction to Android

  23. Application Event Overrides • onCreate – Called when the application is created. Create the application singleton and initialize state variables. • onLowMemory – Lets a well-behaved app free memory when the system is low on resources. • onTrimMemory – Called when the runtime wants the app to reduce its memory. • onConfigurationChanged – Applications are not restarted when the configuration changes, so this must be handled in this method. Introduction to Android

  24. Layouts • As in Swing, Android uses layouts to define the user interface • It is better to use XML to lay out your screen, but you can do it in code • Android has three layouts: Linear, Relative, and Grid • You can nest layouts within layouts Introduction to Android

  25. Linear Layout • Allows you to create a simple UI that aligns a sequence of child views (controls, etc.) in either a vertical or horizontal line. • Simplest and least flexible of the layout managers. Introduction to Android

  26. Relative Layout • You can define the position of each element in terms of its parent and the other Views Introduction to Android

  27. Grid Layout • Uses a grid to organize other Views. • Useful for screens that require alignment in 2 directions. • Supports row and column spanning. Introduction to Android

  28. Layout Guidelines • Avoid redundancy • Don’t nest them too deep • Limit the number of views Introduction to Android

More Related