Translate

domingo, 5 de febrero de 2017

Android key concepts

What is an activity?
An activity is responsible for managing user interaction with a screen of information.
What is a layout file?
A layout defines a set of user interface objects and their position on the screen. A layout is made up of definitions written in XML. Each definition is used to create an object that appears on screen, like a button or some text.
Min sdk
The minimum API Level required for the application to run. The Android system will prevent the user from installing the application if the system's API Level is lower than the value specified in this attribute.
Target sdk version
This attribute informs the system that you have tested against the target version and the system should not enable any compatibility behaviors to maintain your app's forward-compatibility with the target version. The application is still able to run on older versions (down to minSdkVersion).
Max sdk version
An integer designating the maximum API Leven however due to the backwards compatibility is not recomended to declare this attribute.

Resources in Android
You should always externalize application resources such as images and strings from your code, so that you can maintain them independently. You should also provide alternative resources for specific device configurations, by grouping them in specially-named resource directories. At runtime, Android uses the appropriate resource based on the current configuration.

Resource directory
In the /res folder you can have:

  • anim/ - XML files that define tween animations
  • color/ - XML files that define a state list of colors.
  • drawable/ - Bitmap files / Nine-Patches (re-sizable bitmaps) / State lists / Shapes / Animation drawables / Other drawables
  • layout/ - XML files that define a user interface layout.
  • menu/ - XML files that define application menus, such as an Options Menu, Context Menu, or Sub Menu.
  • raw/ - Arbitrary files to save in their raw form.
  • values/ - XML files that contain simple values, such as strings, integers, and colors.
    • arrays.xml for resource arrays (typed arrays).
    • colors.xml for color values
    • dimens.xml for dimension values.
    • strings.xml for string values.
    • styles.xml for styles.
  • xml/ - Arbitrary XML files
Caution in Resources Folder
Never save resource files directly inside the res/ directory—it will cause a compiler error
Files in assets/ are not given a resource ID, so you can read them only using AssetManager.

Assets VS Resources
With resources, there's built-in support for providing alternatives for different languages, OS versions, screen orientations, etc., as described here. None of that is available with assets.

Activity LifeCycle




MethodDescriptionKillable?Next
onCreate()Called when the activity is first created. This is where you should do all of your normal static set up: create views, bind data to lists, etc. This method also provides you with a Bundle containing the activity's previously frozen state, if there was one.Always followed by onStart().NoonStart()
    onRestart()Called after your activity has been stopped, prior to it being started again.Always followed by onStart()NoonStart()
onStart()Called when the activity is becoming visible to the user.Followed by onResume() if the activity comes to the foreground, or onStop() if it becomes hidden.NoonResume()or onStop()
    onResume()Called when the activity will start interacting with the user. At this point your activity is at the top of the activity stack, with user input going to it.Always followed by onPause().NoonPause()
onPause()Called when the system is about to start resuming a previous activity. This is typically used to commit unsaved changes to persistent data, stop animations and other things that may be consuming CPU, etc. Implementations of this method must be very quick because the next activity will not be resumed until this method returns.Followed by either onResume() if the activity returns back to the front, or onStop() if it becomes invisible to the user.Pre-HONEYCOMBonResume()or
onStop()
onStop()Called when the activity is no longer visible to the user, because another activity has been resumed and is covering this one. This may happen either because a new activity is being started, an existing one is being brought in front of this one, or this one is being destroyed.Followed by either onRestart() if this activity is coming back to interact with the user, or onDestroy() if this activity is going away.YesonRestart()or
onDestroy()
onDestroy()The final call you receive before your activity is destroyed. This can happen either because the activity is finishing (someone called finish() on it, or because the system is temporarily destroying this instance of the activity to save space. You can distinguish between these two scenarios with the isFinishing() method.Yesnothing


Fragments