an item: dp/dip: Density independent pixel. sp/sip: Scale independent pixel.Used in font sizes. pt: Point. px: Pixel. Not use layout_width,layout_height match_parent:takes all the space available. wrap_content: uses the space needed fill_parent:equivalent to match_parent
and reference in the application. Declaratively include in /res ,accesing by @<type>/<nname> Are programmatically accessible via the R class (compiled with Android Asset Packaging Tool) Android automatically selects the resource that adapts to the environment Each resource type in a folder / res. drawable: Images, Icons. layout: Layout to organize views. values: string.xml: Text strings colors.xml dimens.xml: font sizes,margins,paddings anim: Animations raw: Other resources like audio or video menu: Menus and dialogs xml: Other xml (preferences, app widget, …) <supports-screens android:anyDensity="true" android:xlargeScreens="true" android:largeScreens="true" android:normalScreens="true" android:smallScreens="true" />
Through code label.setContentDescription(getText(R.string.text_description)); Focus navigation. Next view to receive focus when user navigates <EditText android:id="@id/editText" android:layout_alignBottom="@+id/button" android:layout_toLeftOf="@id/button" android:nextFocusUp="@+id/button" android:nextFocusDown="@+id/button" android:nextFocusLeft="@+id/button" android:nextFocusRight="@+id/button" android:nextFocusForward="@+id/button"/>
event (such as key press or screen touch events) within 5 seconds. Do not block the main UI thread with heavy work Web Service call, Http Request Communication with UI Thread is made with: • Thread / Handler • ThreadPoolExecutor • AsyncTask Goal of AsyncTask is to take care of thread management for you.
tasks without using neither directly nor Handlers Threads, trying these elements in a fully transparent way to the programmer. When we define a AsyncTask class must define the type of three elements, the input parameters, its progress and outcome. Override onPreExecute(),doInBackground(),onPostExecute(),onProgressUpdate() class RequestTask extends AsyncTask<String, String, String>{ @Override protected void onPreExecute() { } @Override protected void onProgressUpdate(Integer... values) { } @Override protected String doInBackground(String... uri) { } @Override protected void onPostExecute(String result) { super.onPostExecute(result); } new RequestTask().execute(url);
the service when the task is complete. Leaving a service running when it’s not needed is one of the worst memory management mistakes an Android app can make. Service problem is always execute in main thread. The best way to limit the lifespan of your service is to use an IntentService, which finishes itself as soon as it's done handling the intent that started it. IntentService always execute in own thread. Allows to launch a service in a new thread, avoiding blocking the main thread. Example:ActivityRecognitionService
portion of a user interface activity. Multiple fragments can be combined. A fragment must always be part of an activity. They emerged to provide greater flexibility to build the user interface Override methods @Override //called when finish onCreate method in activity public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); } @Override public void onCreate(Bundle savedInstanceState) {//inicializar componentes super.onCreate(savedInstanceState); } @Override public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState) { } http://developer.android.com/guide/components/fragments.html
navigation in Action Bar actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); Drop-down Navigation in Action Bar actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST); NavUtils in library support <android.support.v4.view.ViewPager xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/pager" android:layout_width="wrap_content" android:layout_height="wrap_content"/>
view It works with ListView or GridView There are many types of adapter You can perform a custom adapter The most used ArrayAdapter / CursorAdapter The Adapter interacts with a collection of data objects for display in View ArrayList<UniversidadBean> listado=newArrayList<UniversidadBean>(); private ListView lstListado; lstListado=(ListView)getView().findViewById (R.id.LstListado); lstListado.setAdapter (new UniversidadAdapter(this,listado));
ImageView imagen; public TextView nombre; public TextView descripcion; } Improve the performance of listview The viewholder is used to avoid calling findViewById whenever prompted a new row to the adapter. Thus, instead of calling findViewById each time you use the references to the fields you have stored in the viewholder. This pattern will help us to limit the number of calls to findViewById method. The idea would be to call it once, and then save the view daughter that refers to the instance of ViewHolder to be associated with the object by the method convertView View.setTag () Its recommend using a static class to store the items of each row in the view, functioning as a kind of cache for our view.
convertView,ViewGroup parent) { ViewContainer viewContainer; //si es la primera vez que se imprime la fila if(convertView==null){ LayoutInflater inflater = context.getLayoutInflater(); convertView = inflater.inflate(R.layout.row, null,true); //crea una vista para el objeto contenedor viewContainer=new ViewContainer() //obtiene una referencia a todas las vistas de la fila viewContainer.nombre=(TextView)convertView.findViewById(R.id.textView_superior); viewContainer.descripcion=(TextView)convertView.findViewById(R.id.textView_inferior); viewContainer.imagen=(ImageView)convertView.findViewById(R.id.imageView_imagen); //asigna el contenedor de la vista a rowView convertView.setTag(viewContainer); }else{ viewContainer=(ViewContainer) convertView.getTag(); //recicling } //personaliza el contenido de cada fila basándone en su posición viewContainer.nombre.setText(listado.get(position).getNombre()); viewContainer.descripcion.setText(listado.get(position).getDescripcion()); viewContainer.imagen.setImageResource(listado.get(position).getIdImagen()); return(convertView); }
applications Use “PASSIVE_PROVIDER” LocationProvider (instead of “GPS_PROVIDER”) LocationListener has three primary settings: “provider” positioning technology (e.g. GPS, NETWORK) “minTime” requested time (milliseconds) between location updates “minDistance” requested distance (m) that triggers updates if (user_moving){ -Decrease LocationListener “minTime” } else{ if(Stopped for a reasonable amount of time){ -Increase LocationListener “minTime” } }
pm = getPackageManager(); boolean hasCamera = pm.hasSystemFeature(PackageManager.FEATURE_CAMERA); if (hasCamera) { // do things that require the camera } boolean hasBlueTooth = pm.hasSystemFeature(PackageManager.FEATURE_BLUETOOTH); if (hasBlueTooth) { // do things that require the blueTooth } <uses-feature android:name="android.hardware.bluetooth"/> <uses-feature android:name="android.hardware.camera"/>
save the instance state while orientation changes for more responsiveness. Before finish() an activity, onSaveInstanceState() is called to save UI state. Restore the Activity state after being created @Override public void onSaveInstanceState(Bundle savedInstanceState) { // Always call the superclass so it can save the view hierarchy state super.onSaveInstanceState(savedInstanceState); } public void onRestoreInstanceState(Bundle savedInstanceState) { // Always call the superclass so it can restore the view hierarchy super.onRestoreInstanceState(savedInstanceState); }
can be used for identifying and correcting structural problems with your code. Each detection has an associated description and severity level so it can be prioritized. Can be invoked directly from the command-line, automated build system or directly from Eclipse
a new project with code available. Export the project as Java Volley / jar checking only the "src" folder. Volley is a library that facilitates and speeds up the creation of applications that make use of networking in Android handling concurrency and network requests. The advantage is that volley is responsible for managing the request threads transparently to the developer. libs\volley.jar Objects RequestQueue Request: Contains all the necessary details of API calls to Web. For example, the method to use (GET or POST), application data, listeners, error listeners.