Learning android by marko gargenta pdf free download
Get an overview of the Android platform and discover how it fits into the mobile ecosystem Learn about the Android stack, including its application framework, and the structure and distribution of application packages APK Set up your Android development environment and get started with simple programs Use Android's building blocks--Activities, Intents, Services, Content Providers, and Broadcast Receivers Learn how to build basic Android user interfaces and organize UI elements in Views and Layouts Build a service that uses a background process to update data in your application Get an introduction to Android Interface Definition Language AIDL and the Native Development Kit NDK.
ISBN Your tags:. Send-to-Kindle or Email Please login to your account first Need help? Please read our short guide how to send a book to Kindle. The file will be sent to your email address. It may take up to minutes before you receive it. You either start a service or stop it. Also, the service life cycle is more or less controlled by the developer, and not so much by the system. By default, services and activities run on the same main application thread, often called the UI thread.
If a service is doing some processing that takes a while to complete such as performing network calls , you would typically invoke a separate thread to run it. Otherwise, your user interface will run noticeably slower. Content Providers Content providers are interfaces for sharing data between applications. Although small amounts of data can be passed between applications via intents, content providers are much better suited for sharing persistent data between possibly large datasets.
The methods that content providers use to implement the four critical operations are: Operation Method Create insert Read query Update update Delete delete The Android system uses this mechanism all the time. Content provider Figure Contacts application using the Contacts Provider to get the data This separation of data storage and the actual user interface application offers greater flexibility to mash up various parts of the system.
For example, a user could install an alternative address book application that uses the same data as the default Contacts app. Or he could install widgets on the home screen that allow for easy changes in the System Settings, such as turning on or off the WiFi, Bluetooth, or GPS features. Many phone manufacturers take advantage of content providers to add their own applications on top of standard Android to improve the overall user experience, such as HTC Sense.
The insert , update , delete , and query methods look a lot like standard database methods, so it is relatively easy to implement a content provider as a proxy to the database. The receiver is simply dormant code that gets activated by the occurrence of an event to which the receiver is subscribed.
The system itself broadcasts events all the time. For example, when an SMS arrives, a call comes in, the battery runs low, or the system completes booting up, all those events are broadcast, and any number of receivers could be triggered by them. But when triggered, they get to execute some code, such as starting an activity, a service, or something else.
In our sample app mentioned earlier, we want to trigger the update of the local data from the cloud every once in a while. To do that, we can set up an alarm that fires a broadcast intent on some interval, and that intent triggers our receiver to start the refresh service.
So we have an intent triggering a receiver via one type of intent that later starts a service via another type of intent. This chaining of intents is common in Android and provides for a loosely coupled architecture.
Application Context So far you have seen activities, services, content providers, and broadcast receivers. Together, they make up an application.
Think of an application in Android as a container to hold together your blocks. Your activities, services, providers, and receivers do the actual work. The container that they work in is the shared Linux process with common Dalvik VM, private filesystem, shared resources, and similar things. To use our website analogy, an app would be the website domain. Users never really go to Amazon. So web pages and web services are building blocks for a website, and the website itself is just a container to hold them all together under one roof.
This is very similar to what an Android application does for its components. Application context refers to the application environment and the process within which all its components are running see Figure It allows applications to share the data and resources between various building blocks. Application context The application context is uniquely identified on a device based on the package name of that application.
For example, com. There cannot be another app with the same package name unless it comes from us, and we want to use shared user IDs. An application context gets created whenever the first component of this application starts up, regardless of whether that component is an activity, a service, or something else. The application context lives as long as your application is alive.
You can easily obtain a reference to the context by calling Context. Keep in mind that activities and services are already subclasses of the context, and therefore inherit all its methods. Summary In this chapter, you learned about some of the most important Android application components. It should cover all main building blocks and their typical usage. Provide motivation There should be a good reason to use a specific feature. A great example app will defend the most effective design that also relies on Android building blocks.
Be familiar The example application should be simple to understand. We want to focus on software design and implementation, and not on explaining user features.
The Yamba Application The application we picked for this book is a Twitter-like application. Yamba covers most of the main Android building blocks in a natural way. Services such as Twitter are more or less familiar to most people, so the features of the application do not require much explanation.
We are using the same Twitter API. However, Twitter. Although we could implement OAuth in Yamba, we felt that doing so dramatically changes our learning objectives and the flow of the material. OAuth would take us on a tangent that is not primary to learning Android development philosophy.
Additionally, when Marko runs Android training courses, expecting students to have Twitter accounts try that in China! Sometimes our test code may seem to be doing just that. So we have set up our own instance of a cloud service adhering to same Twitter API as the real Twitter. As such, it is designed for learning purposes and testing of your app. The following figures show what a finished product could look like. Figure shows how Yamba displays a list of status messages from your friends.
Figure shows the initial Yamba screen, and Figure shows the user preferences. Initially, the app will not do much, but it will grow organically one step at a time. Always whole and complete The application must always work. But we are going to cross those bridges as we get to them, providing the motivation for refactoring along the way.
This process will teach you about some general software development best practices as well. These are the components from which we put together an application. Figure shows the design of the entire Yamba application, which incorporates most of the main Android building blocks. Yamba design diagram To help understand the diagrams as we keep moving through the the design, Figure provides a quick legend of the design language that we have developed specifically for purposes of illustrating how Yamba comes together.
Design language Part 1: Android User Interface This part, covered in Chapters 7 and 8, will focus on developing the first component of the Yamba application: the Status Update screen.
Our tasks are building an activity, networking and multithreading, and debugging: Building an activity We are going to start by introducing the Android user interface UI model. In its UI, Android is quite different from some other paradigms that you might be familiar with.
In this chapter, you will learn how to develop the user interface, as shown in Figure , where the user updates her status. You will learn about views and layouts, units in Android, how to work with images, and how to make the UI look pretty. Networking and multithreading Once we have a working screen, we will want to post the user input to the cloud service. For that purpose, we are going to use a library to help us with the Twitter API web service calls.
Debugging Android apps A few things are going to go wrong in this section of the book. This is by design, because debugging is a normal part of application development. Debugging will become second nature to you. Fragments Android 3. The need to handle multiple screen sizes and orientations led to the introduction of fragments. We will tackle this UI framework by taking what we have done before and converting them over to this new approach.
Part 2: Intents, ActionBar, and More This part, covered in Chapter 9, is about using Android intents as a way to connect multiple parts together. At the end of this part, your Yamba application will have two screens: one for status updates and the other for setting up the preferences. At this point, Yamba is configurable for various users and starts being a useful app. You will see the steps involved and understand what it takes to create new screens. You will also learn about intents and how to send these to open up a specific activity.
You will gain a deeper understanding of how the operating system is put together, and you will also learn more about Android security. Part 3: Android Services This part, covered in Chapter 10, introduces background services.
They allow a process to run in the background without requiring any user interface. In this section, you will also learn about multithreading considerations as they apply to background services. Intent services These are a convenient way to run a task off the main thread so that thread can continue to handle user interaction. Part 4: Content Providers We now have the data from our refresh service, so we need a place to store it.
They form very powerful components that allow our tiny UI to connect to very large datasets in an efficient and scalable manner. In other words, users will be able to use Yamba in the real world without any performance hits in the long run. In this part, covered in Chapter 12, the Yamba application will get the much-needed TimelineAc tivity and a way for the user to see what his friends are chatting about online. Part 6: Broadcast Receivers Here we develop a third activity, doing so in multiple stages.
It will work, but will not be as optimal as it could be. This goal will introduce us to one type of broadcast receiver. Timeline receiver This type of receiver will exist only at certain times. Part 8: Networking and the Web HTTP Up till now we have provided the underlying communication piece to our example application via a library. Part 9: Live Wallpaper and Handlers As a final piece to the application, we wanted to provide some more interaction at a system level.
One of those ways is a fun, recently added concept in Android called Live Wallpaper, which runs on the home screen of the device. We build out a basic Live Wallpaper that interacts with the user and displays the messages communicated through the backend service. We also cover an important class called the Handler that enables another means to interact with the main UI thread from a different thread. Summary This chapter is intended as a road map for the next eight chapters. By the end of all these iterations, you will have built a medium-size Android app from scratch.
Even more, you will understand various constructs and how to put them together into a meaningful whole. You will create your first activity, create an XML layout for it, and see how to connect it to your Java code. You will learn about views a. By the end of this chapter, you will have written your own Twitter-like Android app. The app will feature a single screen that will prompt the user for her current status update and post that update online.
They are quite different but often are used together to get the job done. You write tags and specify elements to appear on your screen. If you have ever handcoded an HTML page, you did pretty much the same work as creating an Android screen.
It is similar to many UI toolkits in other languages as well. Basically, if you want to create a button programmatically, you have to declare the button variable, create an instance of it, add it to a container, and set any button properties that may make sense, such as color, text, text size, background, and so on. All in all, you end up writing quite a few lines of Java.
Everything you can do declaratively, you can also do programmatically. But Java also allows you to specify what happens when that button is actually clicked. This is the main advantage of a programmatic approach to the user interface.
The Best of Both Worlds So which approach to use? The best practice is to use both. Use the declarative XML approach to declare everything about the user interface that is static, such as the layout of the screen, all the widgets, etc. Then switch to a programmatic Java approach to define what goes on when the user interacts with the various widgets in the user interface.
Views and Layouts Android organizes its UI elements into views and layouts. Everything you see, such as a button, label, or text box, is a view. Layouts organize views, such as grouping together a button and label or a group of these elements. Views in Android are sometimes referred to as widgets. A layout can contain other children. Layouts and views relationship Some of the most common layouts follow.
There are others, but they are used less frequently. LinearLayout LinearLayout is one of the simplest and most common layouts see Figure It simply lays out its children next to one another, either horizontally or vertically. The order of the children matters. As LinearLayout asks its children how much space they need, it allocates the desired space to each child in the order it is added.
Its valid options are vertical or horizontal. TableLayout TableLayout lays out its children in a table, and the views it contains are TableRow widgets see Figure Each TableRow represents a row in a table and can contain other UI widgets.
TableRow widgets are laid out next to each other horizontally, like LinearLayout with a horizontal orientation. TableLayout FrameLayout FrameLayout places its children on top of each other so that the latest child is covering the previous one, like a deck of cards see Figure This layout policy is useful for tabs, as one example.
FrameLayout is also used as a placeholder for other widgets that will be added programmatically at some later point in time. For instance, if you have a two-by-two matrix of widgets, you can lay them out in a single RelativeLayout instead of two horizontal LinearLayouts within a vertical Lin earLayout.
By streamlining the number of layouts you use, RelativeLayout can minimize the total number of widgets that need to be drawn, thus improving the overall performance of your application. Once hard to use, RelativeLayout is becoming the most versatile and efficient layout of them all. You will get a dialog window asking you about your new Android project see Figure New Project dialog Application Name This is the name of your application as generally visible to the users.
It can be pretty much any text, and you can easily change it later. It is a good idea not to use any spaces in your project name. This makes it easier to access from the command line later. Enter Yamba here. In a nutshell, you want to use the reverse of your domain name for your package. At this point, this is a business choice concerning how far back you want to support your app.
In other words, should this app be able to run on very old devices? An analogy to this would be building a website that has to work on IE6, where you have to deal with a lot of quirks. In our case, we choose that the app should work on API level 11 Android 3.
This could be any Android platform, either standard or proprietary. The next screen lets you choose whether to create a custom launcher icon we do! The Configure Launcher Icon diagram in Figure gives you an opportunity to create a custom icon that the users will click to launch your application. You can load an image from your computer, create an icon using the clip art image, or make some text be that image.
Go ahead and play with the options! They are all the same image, but with different sizes. Some older devices have about dots per inch dpi , whereas the newer ones are pushing dpi.
Depending on the type of the display, Android OS will pick the right image to render. Configure the Launcher Icon Once you are happy with that image, click Next. On the Create Activity screen, choose to create an activity, and leave it at just the Blank Activity.
On the Blank Activity screen in Figure , pick the name of the activity. Thus, for the activity name, you must adhere to Java class naming conventions. Doing that simply means using upper camel case. Blank Activity setup Typically, an activity will have a layout file associated with it.
This file is an XML file. While we have a strong naming convention in Java, the XML resources could be named both using the camel case as well as the underscores. Click Finish.
Eclipse will recognize this file and open it using a graphical layout. As a matter of fact, this file should have already been opened when you created the project initially. Notice that you can toggle between the graphical layout and the actual generated code via the tabs at the bottom of the window. Think of this tool as a Dreamweaver or similar HTML authoring tool where you can easily create a UI, and the tool generates the underlying code. Now you have a blank screen to work with.
This is the big white area. We discussed the layout types earlier in this chapter. This will be a Button widget. Locate it under the Form Widgets section of the Palette and drag it to the top-right corner of your screen. The button will sort of glue to that corner. Next, we need a big text area to type our character status update. You can locate this widget under the Text Fields section of the Palletes. Although there are a few choices, most of them are the same element with just a different visual appearance.
Pick Multiline Text for our case. Do the same for the height. This will be the ID of this particular piece of text.
In our case, we will want to be able to lookup the button and the text area in Java. To do that, we want to assign them meaningful IDs. Do the same for the status text area and type editStatus for the ID. You could also peek at the actual generated code by clicking the tab at the bottom of the screen. Example contains the source code for our StatusActivity layout. More on strings later in this chapter. Although you could enter a value in pixels, inches, or something similar, that is not a good practice.
Because your application could run on many different devices with various screen sizes, you want to use relative size for your components, not an absolute size. Some developers still use the older name, which still works. Values can be top, center, left, and so on. This property simply specifies the text to show in the widget. Best practice is to define all text in a strings.
But widgets that you need to manipulate later from Java do need ids. So layouts are defined in their own resources, and all text values such as button text, title text, etc. This allows you later to provide multiple versions of string resources for various languages, such as English, Japanese, or Russian.
As usual, Eclipse ADT provides an easy editor to manage known resource types, which include strings. The editor window looks like Figure Example shows what our strings. One is by declaring it in XML, which is what we just did, and we got as far as we could for now. The other one is to build it programmatically in Java. We also said earlier that the best practice is to get as far as possible in XML and then switch over to Java. Our Java class for this is StatusActivity.
The class is part of the com. We as developers do not control what state the activity is in, but we do get to say what happens during a transition to a particular state. This sort of programming, when we subclass a system class and fill in the blanks, is also known as the Template pattern. In addition to doing some standard housekeeping, our onCreate will carry out two major tasks that the application needs done just once, at the beginning: set up our button so it responds to clicks, and connect to the cloud.
Notice that onCreate takes a Bundle as a parameter. This is a small amount of data that can be passed into the activity once it is being shut down so that the new instance of this activity can recreate its original state.
This is a common case when rotating the screen, in which case the activity typically gets reinitialized. Keep in mind that whenever you override a method, you first want to make a call to the original method provided by the parent. But now you have a placeholder where you can add your own code. In other words, write some Java code that opens up your XML layout file, parses it, and for each element in XML, creates a corresponding Java object in your memory space.
For each attribute of a particular XML element, this code will set that attribute on your Java object. The line of code that does all this is setContentView R. Similarly, R. This setContentView method does a lot of work, in other words. At the end of this one line, our screen is ready for drawing. The Eclipse boilerplate code also includes the onCreateOptionsMenu method. Bundle; import android. We override the onCreate method in order to add some specific logic.
Remember to call the super in all the life cycle methods. This is the main work of this entire code. For each element in that XML file, the call creates the corresponding Java object of the same class as the name. Initializing Objects Once we inflate the objects into the Java memory space, we have to find the objects that we actually care about and assign them to Java variables.
To do that, we declare these variables, usually as private and class-global. Next, we use findViewById method to look them up This is where we define the Java variable as private and class-global. To do that, you need to define a method named on Click and put the code there that you want executed. You also have to run the setOnClickListener method on the Button. Pass this as an argument to setOnClick Listener, because your current object the activity is where you define onClick.
Example shows our first version of StatusActivity. Log; import android. Menu; import android. View; import android. OnClickListener; import android. Button; import android. Register the button to notify this i. The method that is called when button is clicked, as part of the OnClickListen er interface. We look up the value of the actual text of the status in the UI.
Use the log system to print out the value so we know this is working. Logging Messages in Android Android offers a system-wide logging capability. You can log from anywhere in your code by calling Log.
Android on x86 by Iggy Krajci, Darren Cummings - Apress The book makes the case for adapting your applications onto Intel's x86 architecture, including discussions of the business potential, the changing landscape of the Android marketplace, and the unique opportunities that arise from x86 devices.
Android Cookbook by Ian F. The double-blind peer reviewed was. Learn Android Studio covers Android Studio and its rich tools ecosystem, including Git and Gradle: this book covers how Android Studio works seamlessly with Git, for source control, and Gradle, a build and test tool.
Four complete Android projects accompany this volume and are available for download from a public Git repository. With this book, you learn the latest and most. Create the perfectly customized system by unleashing the power of Android OS on your embedded device About This Book Understand the system architecture and how the source code is organized Explore the power of Android and customize the build system Build a fully customized Android version as per your requirements Who This Book Is For If you are a Java programmer who wants to customize, build, and deploy your own Android version using embedded programming, then this book is for.
Books Learning Android. Author : Raj Amal W. Author : Oleg Skulkin,Donnie Tindall,Rohit Tamma Publisher : Packt Publishing Ltd Release Date : ISBN : GET THIS BOOK Learning Android Forensics A comprehensive guide to Android forensics, from setting up the workstation to analyzing key artifacts Key Features Get up and running with modern mobile forensic strategies and techniques Analyze the most popular Android applications using free and open source forensic tools Learn malware detection and analysis techniques to investigate mobile cybersecurity incidents Book Description Many forensic examiners rely on commercial, push-button tools to retrieve and analyze data, even though there is no tool that does either of these jobs perfectly.
0コメント