archive-com.com » COM » T » TECHOTOPIA.COM

Total: 1018

Choose link from "Titles, links and description words view":

Or switch to "Titles and links view".
  • Testing Android Studio Apps on a Physical Android Device - Techotopia
    to the Android device and check for the presence of the dialog shown in Figure 6 9 seeking permission to Allow USB debugging Enable the checkbox next to the option that reads Always allow from this computer before clicking on OK Repeating the adb devices command should now list the device as being available List of devices attached 015d41d4454bf80c device In the event that the device is not listed try logging out and then back in to the Mac OS X desktop and if the problem persists rebooting the system eBookFrenzy com Purchase the fully updated Android 6 Edition of this Android Studio Development Essentials publication in eBook 9 99 or Print 38 99 format Android Studio Development Essentials Android 6 Edition Print and eBook ePub PDF Kindle editions contain 65 chapters Windows ADB Configuration The first step in configuring a Windows based development system to connect to an Android device using ADB is to install the appropriate USB drivers on the system In the case of some devices the Google USB Driver must be installed a full listing of devices supported by the Google USB driver can be found online at http developer android com sdk win usb html To install this driver perform the following steps 1 Launch Android Studio and open the Android SDK Manager either by selected Configure SDK Manager from the Welcome screen or using the Tools Android SDK Manager menu option when working on an existing project 2 Scroll down to the Extras section and check the status of the Google USB Driver package to make sure that it is listed as Installed 3 If the driver is not installed select it and click on the Install packages button to initiate the installation 4 Once installation is complete close the Android SDK Manager For Android devices not supported by the Google USB driver it will be necessary to download the drivers provided by the device manufacturer A listing of drivers and download information can be obtained online at http developer android com tools extras oem usb html When an Android device is attached to a Windows system it is configured as a Portable Device In order for the device to connect to ADB it must be configured as an Android ADB Composite Device First connect the Android device to the computer system if it is not currently connected Next display the Control Panel and select Device Manager In the resulting dialog check for a category entitled Other Devices Unfold this category and check to see if the Android device is listed in the case of Figure 6 5 a Nexus 7 has been detected Figure 6 5 Right click on the device name and select Update Driver Software from the menu Select the option to Browse my computer for driver software and in the next dialog keep the Include subfolder option selected and click on the Browse button Navigate to the location into which the USB drivers were installed In the case of the

    Original URL path: http://www.techotopia.com/index.php/Testing_Android_Studio_Apps_on_a_Physical_Android_Device (2016-02-13)
    Open archived version from archive


  • The Basics of the Android Studio Code Editor - Techotopia
    the Split Vertically or Split Horizontally menu option Figure 7 5 for example shows the splitter in action with the editor split into three panels Figure 7 5 The orientation of a split panel may be changed at any time by right clicking on the corresponding tab and selecting the Change Splitter Orientation menu option Repeat these steps to unsplit a single panel this time selecting the Unsplit option from the menu All of the split panels may be removed by right clicking on any tab and selecting the Unsplit All menu option Window splitting may be used to display different files or to provide multiple windows onto the same file allowing different areas of the same file to be viewed and edited concurrently Code Completion The Android Studio editor has a considerable amount of built in knowledge of Java programming syntax and the classes and methods that make up the Android SDK as well as knowledge of your own code base As code is typed the editor scans what is being typed and where appropriate makes suggestions with regard to what might be needed to complete a statement or reference When a completion suggestion is detected by the editor a panel will appear containing a list of suggestions In Figure 7 6 for example the editor is suggesting possibilities for the beginning of a String declaration Figure 7 6 eBookFrenzy com Purchase the fully updated Android 6 Edition of this Android Studio Development Essentials publication in eBook 9 99 or Print 38 99 format Android Studio Development Essentials Android 6 Edition Print and eBook ePub PDF Kindle editions contain 65 chapters If none of the auto completion suggestions are correct simply keep typing and the editor will continue to refine the suggestions where appropriate To accept the top most suggestion simply press the Enter or Tab key on the keyboard To select a different suggestion use the arrow keys to move up and down the list once again using the Enter or Tab key to select the highlighted item Completion suggestions can be manually invoked using the Ctrl Space keyboard sequence This can be useful when changing a word or declaration in the editor When the cursor is positioned over a word in the editor that word will automatically highlight Pressing Ctrl Space will display a list of alternate suggestions To replace the current word with the currently highlighted item in the suggestion list simply press the Tab key In addition to the real time auto completion feature the Android Studio editor also offers a system referred to as Smart Completion Smart completion is invoked using the Shift Ctrl Space keyboard sequence and when selected will provide more detailed suggestions based on the current context of the code Pressing the Shift Ctrl Space shortcut sequence a second time will provide more suggestions from a wider range of possibilities Code completion can be a matter of personal preference for many programmers In recognition of this fact Android Studio provides a

    Original URL path: http://www.techotopia.com/index.php/The_Basics_of_the_Android_Studio_Code_Editor (2016-02-13)
    Open archived version from archive

  • The Anatomy of an Android Studio Android Application - Techotopia
    type of Intent the Broadcast Intent is a system wide intent that is sent out to all applications that have registered an interested Broadcast Receiver The Android system for example will typically send out Broadcast Intents to indicate changes in device status such as the completion of system start up connection of an external power source to the device or the screen being turned on or off A Broadcast Intent can be normal asynchronous in that it is sent to all interested Broadcast Receivers at more or less the same time or ordered in that it is sent to one receiver at a time where it can be processed and then either aborted or allowed to be passed to the next Broadcast Receiver Broadcast Receivers Broadcast Receivers are the mechanism by which applications are able to respond to Broadcast Intents A Broadcast Receiver must be registered by an application and configured with an Intent Filter to indicate the types of broadcast in which it is interested When a matching intent is broadcast the receiver will be invoked by the Android runtime regardless of whether the application that registered the receiver is currently running The receiver then has 5 seconds in which to complete any tasks required of it such as launching a Service making data updates or issuing a notification to the user before returning Broadcast Receivers operate in the background and do not have a user interface eBookFrenzy com Purchase the fully updated Android 6 Edition of this Android Studio Development Essentials publication in eBook 9 99 or Print 38 99 format Android Studio Development Essentials Android 6 Edition Print and eBook ePub PDF Kindle editions contain 65 chapters Android Services Android Services are processes that run in the background and do not have a user interface They can be started and subsequently managed from activities Broadcast Receivers or other Services Android Services are ideal for situations where an application needs to continue performing tasks but does not necessarily need a user interface to be visible to the user Although Services lack a user interface they can still notify the user of events using notifications and toasts small notification messages that appear on the screen without interrupting the currently visible activity and are also able to issue Intents Services are given a higher priority by the Android runtime than many other processes and will only be terminated as a last resort by the system in order to free up resources In the event that the runtime does need to kill a Service however it will be automatically restarted as soon as adequate resources once again become available A Service can reduce the risk of termination by declaring itself as needing to run in the foreground This is achieved by making a call to startForeground This is only recommended for situations where termination would be detrimental to the user experience for example if the user is listening to audio being streamed by the Service Example situations where a Service might

    Original URL path: http://www.techotopia.com/index.php/The_Anatomy_of_an_Android_Studio_Android_Application (2016-02-13)
    Open archived version from archive

  • Handling Android Activity State Changes in Android Studio - Techotopia
    updated Android 6 Edition of this Android Studio Development Essentials publication in eBook 9 99 or Print 38 99 format Android Studio Development Essentials Android 6 Edition Print and eBook ePub PDF Kindle editions contain 65 chapters The appearance of the user interface such as text entered into a text field but not yet committed to the application s internal data model is referred to as the dynamic state since it is typically only retained during a single invocation of the application and also referred to as user interface state or instance state Understanding the differences between these two states is important because both the ways they are saved and the reasons for doing so differ The purpose of saving the persistent state is to avoid the loss of data that may result from an activity being killed by the runtime system while in the background The dynamic state on the other hand is saved and restored for reasons that are slightly more complex Consider for the sake of an example that an application contains an activity which we will refer to as Activity A containing a text field and some radio buttons During the course of using the application the user enters some text into the text field and makes a selection from the radio buttons Before performing an action to save these changes however the user then switches to another activity causing Activity A to be pushed down the Activity Stack and placed into the background After some time the runtime system ascertains that memory is low and consequently kills Activity A to free up resources As far as the user is concerned however Activity A was simply placed into the background and is ready to be moved to the foreground at any time On returning Activity A to the foreground the user would quite reasonably expect the entered text and radio button selections to have been retained In this scenario however a new instance of Activity A will have been created and if the dynamic state was not saved and restored the previous user input lost The main purpose of saving dynamic state therefore is to give the perception of seamless switching between foreground and background activities regardless of the fact that activities may actually have been killed and restarted without the user s knowledge The mechanisms for saving persistent and dynamic state will become clearer in the following sections of this chapter The Android Activity Lifecycle Methods As previously explained the Activity class contains a number of lifecycle methods which act as event handlers when the state of an Activity changes The primary methods supported by the Android Activity class are as follows onCreate Bundle savedInstanceState The method that is called when the activity is first created and the ideal location for most initialization tasks to be performed The method is passed an argument in the form of a Bundle object that may contain dynamic state information typically relating to the state of the user interface

    Original URL path: http://www.techotopia.com/index.php/Handling_Android_Activity_State_Changes_in_Android_Studio (2016-02-13)
    Open archived version from archive

  • Android Activity State Changes - An Android Studio Example - Techotopia
    Print 38 99 format Android Studio Development Essentials Android 6 Edition Print and eBook ePub PDF Kindle editions contain 65 chapters Overriding the Activity Lifecycle Methods At this point the project contains a single activity named StateChangeActivity which is derived from the Android ActionBarActivity class The source code for this activity is contained within the StateChangeActivity java file which should already be open in an editor session and represented by a tab in the editor tab bar In the event that the file is no longer open navigate to it in the Project tool window panel app java com ebookfrenzy statechange StateChangeActivity and double click on it to load the file into the editor Once loaded the code should read as follows package com ebookfrenzy statechange import android support v7 app ActionBarActivity import android os Bundle import android view Menu import android view MenuItem public class StateChangeActivity extends ActionBarActivity Override protected void onCreate Bundle savedInstanceState super onCreate savedInstanceState setContentView R layout activity state change Override public boolean onCreateOptionsMenu Menu menu Inflate the menu this adds items to the action bar if it is present getMenuInflater inflate R menu menu state change menu return true Override public boolean onOptionsItemSelected MenuItem item Handle action bar item clicks here The action bar will automatically handle clicks on the Home Up button so long as you specify a parent activity in AndroidManifest xml int id item getItemId if id R id action settings return true return super onOptionsItemSelected item So far the only lifecycle method overridden by the activity is the onCreate method which has been implemented to call the super class instance of the method before setting up the user interface for the activity We will now modify this method so that it outputs a diagnostic message in the Android Studio LogCat panel each time it executes For this we will use the Log class which requires that we import android util Log and declare a tag that will enable us to filter these messages in the log output package com ebookfrenzy statechange import android support v7 app ActionBarActivity import android os Bundle import android view Menu import android view MenuItem import android util Log public class StateChangeActivity extends ActionBarActivity private static final String TAG com ebookfrenzy StateChange Override protected void onCreate Bundle savedInstanceState super onCreate savedInstanceState setContentView R layout activity state change Log i TAG onCreate The next task is to override some more methods with each one containing a corresponding log call These override methods may be added manually or generated using the Alt Insert keyboard shortcut as outlined in the chapter entitled The Basics of the Android Studio Code Editor Note that the Log calls will still need to be added manually if the methods are being auto generated Override protected void onStart super onStart Log i TAG onStart Override protected void onResume super onResume Log i TAG onResume Override protected void onPause super onPause Log i TAG onPause Override protected void onStop super onStop Log i TAG onStop Override

    Original URL path: http://www.techotopia.com/index.php/Android_Activity_State_Changes_-_An_Android_Studio_Example (2016-02-13)
    Open archived version from archive

  • Saving and Restoring Activity State in Android Studio - Techotopia
    to be saved beyond the default functionality provided by the user interface view components the Bundle class provides a container for storing data using a key value pair mechanism The keys take the form of string values whilst the values associated with those keys can be in the form of a primitive value or any object that implements the Android Parcelable interface A wide range of classes already implements the Parcelable interface Custom classes may be made parcelable by implementing the set of methods defined in the Parcelable interface details of which can be found in the Android documentation at http developer android com reference android os Parcelable html The Bundle class also contains a set of methods that can be used to get and set key value pairs for a variety of data types including both primitive types including Boolean char double and float values and objects such as Strings and CharSequences For the purposes of this example and having disabled the automatic saving of text for the EditText view we need to make sure that the text entered into the EditText field by the user is saved into the Bundle object and subsequently restored This will serve as a demonstration of how to manually save and restore state within an Android application and will be achieved using the putCharSequence and getCharSequence methods of the Bundle class respectively Saving the State The first step in extending the StateChange application is to make sure that the text entered by the user is extracted from the EditText component within the onSaveInstanceState method of the StateChangeActivity activity and then saved as a key value pair into the Bundle object In order to extract the text from the EditText object we first need to identify that object in the user interface Clearly this involves bridging the gap between the Java code for the activity contained in the StateChangeActivity java source code file and the XML representation of the user interface contained within the activity state change xml resource file In order to extract the text entered into the EditText component we need to gain access to that user interface object Each component within a user interface has associated with it a unique identifier By default the Designer tool constructs the ID for a newly added component from the object type If more than one view of the same type is contained in the layout the type name is followed by a sequential number though this can and should be changed to something more meaningful by the developer As can be seen by checking the Component panel within the Android Studio main window when the activity state change xml file is selected and the Designer tool displayed the EditText component has been assigned the ID editText Figure 13 1 eBookFrenzy com Purchase the fully updated Android 6 Edition of this Android Studio Development Essentials publication in eBook 9 99 or Print 38 99 format Android Studio Development Essentials Android 6 Edition Print and eBook

    Original URL path: http://www.techotopia.com/index.php/Saving_and_Restoring_Activity_State_in_Android_Studio (2016-02-13)
    Open archived version from archive

  • Understanding Android Views, View Groups and Layouts in Android Studio - Techotopia
    be set on each child to specify how much of the layout space that child should occupy relative to other children TableLayout Arranges child views into a grid format of rows and columns Each row within a table is represented by a TableRow object child which in turn contains a view object for each cell FrameLayout The purpose of the FrameLayout is to allocate an area of screen typically for the purposes of displaying a single view If multiple child views are added they will by default appear on top of each other positioned in the top left hand corner of the layout area Alternate positioning of individual child views can be achieved by setting gravity values on each child For example setting a center vertical gravity on a child will cause it to be positioned in the vertical center of the containing FrameLayout view RelativeLayout Probably the most powerful and flexible of the layout managers this allows child views to be positioned relative both to each other and the containing layout view through the specification of alignments and margins on child views For example child View A may be configured to be positioned in the vertical and horizontal center of the containing RelativeLayout view View B on the other hand might also be configured to be centered horizontally within the layout view but positioned 30 pixels above the top edge of View A thereby making the vertical position relative to that of View A The RelativeLayout manager can be of particular use when designing a user interface that must work on a variety of screen sizes and orientations AbsoluteLayout Allows child views to be positioned at specific X and Y coordinates within the containing layout view Use of this layout is discouraged since it lacks the flexibility to respond to changes in screen size and orientation GridLayout The GridLayout is a relatively new layout manager that was introduced as part of Android 4 0 A GridLayout instance is divided by invisible lines that form a grid containing rows and columns of cells Child views are then placed in cells and may be configured to cover multiple cells both horizontally and vertically allowing a wide range of layout options to be quickly and easily implemented Gaps between components in a GridLayout may be implemented by placing a special type of view called a Space view into adjacent cells or by setting margin parameters When considering the use of layouts in the user interface for an Android application it is worth keeping in mind that as will be outlined in the next section these can be nested within each other to create a user interface design of just about any necessary level of complexity eBookFrenzy com Purchase the fully updated Android 6 Edition of this Android Studio Development Essentials publication in eBook 9 99 or Print 38 99 format Android Studio Development Essentials Android 6 Edition Print and eBook ePub PDF Kindle editions contain 65 chapters The View Hierarchy Each view

    Original URL path: http://www.techotopia.com/index.php/Understanding_Android_Views,_View_Groups_and_Layouts_in_Android_Studio (2016-02-13)
    Open archived version from archive

  • A Guide to the Android Studio Designer Tool - Techotopia
    the behavior and appearance of that view The Designer s properties panel provides access to the properties of the currently selected view in the layout allowing changes to be made E Toolbar The Designer toolbar provides quick access to a wide range of options including amongst other options the ability to zoom in and out of the device screen layout change the device model currently displayed rotate the layout between portrait and landscape and switch to a different Android SDK API level The toolbar also has a set of context sensitive buttons which will appear when relevant view types are selected in the device screen layout F Mode Switching Tabs The tabs located along the lower edge of the Designer provide a way to switch back and forth between the Designer tool s text and design modes Text Mode It is important to keep in mind when using the Android Studio Designer tool that all it is really doing is providing a user friendly approach to creating XML layout resource files At any time during the design process the underlying XML can be viewed and directly edited simply by clicking on the Text tab located at the bottom of the Designer tool panel To return to design mode simply click on the Design tab Figure 15 2 highlights the key areas of the Android Studio Designer tool in text mode Figure 15 2 A Editor The editor panel displays the XML that makes up the current user interface layout design This is the full Android Studio editor environment containing all of the features previously outlined in the The Basics of the Android Studio Code Editor chapter of this book B Preview As changes are made to the XML in the editor these changes are visually reflected in the preview window This provides instant visual feedback on the XML changes as they are made in the editor thereby avoiding the need to switch back and forth between text and design mode to see changes Whilst the preview does not allow direct manipulation of the views double clicking on a view in the preview will automatically switch to design mode and preselect the corresponding view in the device screen layout C Toolbar The toolbar in text mode provides a subset of those functions available in design mode with the addition of a button to take a screenshot of the current device screen layout D Mode Switching Tabs The tabs located along the lower edge of the Designer provide a way to switch back and forth between the Designer tool s text and design modes eBookFrenzy com Purchase the fully updated Android 6 Edition of this Android Studio Development Essentials publication in eBook 9 99 or Print 38 99 format Android Studio Development Essentials Android 6 Edition Print and eBook ePub PDF Kindle editions contain 65 chapters Setting Properties The properties panel provides access to all of the available settings for the currently selected component Clicking in the panel and typing characters will

    Original URL path: http://www.techotopia.com/index.php/A_Guide_to_the_Android_Studio_Designer_Tool (2016-02-13)
    Open archived version from archive



  •