Ir al contenido principal

Entradas

Android - Basic Steps (Alarms)

Alarms Remain active even if the device is asleep Are canceled on device shutdown/restart AlarmManager To get a reference use getSystemService(Context.ALARM_SERVICE) Methods Create Alarm set(...) Repeat setRepeating() setInexactRepeating() Alarm Type Constants RTC_WAKEUP - Execute the task at specific wall clock time. Wake up the device Use System.currentTimeMillis() to calculate the time RTC - Execute the task at specific wall clock time. Not wake up the device ELAPSE_REALTIME -  (time since boot, including sleep) Use  SystemClock.elapsedRealtime() to calculate the time ELAPSE_REALTIME_WAKEUP - 

Android - Basic Steps (Thread)

Thread UI Thread - Is the main thread UI Toolkit is not thread-safe Methods The following methods allows to  run in the UI Thread  View.post(Runnable r) Activity.runOnUiThread(Runnable r) AsyncTask Manage the Backgroud Thread & UI Thread Used for relative short tasks that lasting few seconds Background Thread Performs work Indicate progress UI Thread Does Setup Publishes intermediate progress Uses Results Workflow onPreExecute() Run in UI Thread before doInBackground() Do the setup doInBackground() Do the work in the background Return the result in a Result object pulishProgress() This method may be invoked onProgressUpdate() If pulishProgress() is invoked then this method continue Runs in the UI Thread onPostExecute Runs after  doInBackground() Handler Handle two threads of any kind One thread can hand off work to another thread by messages & posting runnables to handler associa...

Android - Basic Steps (Notifications)

User Notifications Types: Toast Notification Area Notifications Tip To use the notification vibration, establish the permission in the AndroidManifest.xml file    <uses-permission android:name="android.permission.VIBRATE" >     </uses-permission> Broadcast Base class for components that receive and react to events When event occur is represented as Intent, then are broadcast to system The Intent routes to BroadcastReceiver The BroadcastReceiver receive on the method onReceive() Broadcast Events can be broadcast in Order or Normal way Normal - Undefined order and if there are two or more BroadcastReceivers can process the event at the same time. Order - Deliver the intent one at the time in priority order Can also be Sticky or Not Sticky Sticky   Store intent after initial broadcast Is useful to record system changes like the battery status Is disposed after the event finish  Non Stick...

Github

Github Commands Upload the changes to GIT git add . git commit -m "Added associations" git push origin master Commands git init Initialize a Git repository git status Check if there are changes git add file_name Add specific file git add '*.txt' Add a type of files git rm '<file_name>' Delete a file git commit -m "Comment" Store our staged change git log Show all the changes git remote add origin https://github.com/<repository>/<repository_name>.git Push our local repository to Github server git push -u origin master  Push the changes to the server repo origin - is the name of the remote master - is the name of the branch -u - save the parameters, so the second time only type git push git pull origin master Down the changes from the server repo git diff HEAD Get the differences from our most recent commit git diff --staged See the changes you just staged git ...

Android - Basic Steps (UI)

View Elements Button ToggleButton Checkbox RatingBar AutoCompleteTextView ViewGroups RadioGroup TimePicker DatePicker WebView MapView Gallery Spinner Adapters & AdapterViews AdapterView are Views managed by an Adapter, who manage the data and provides data views AdapterView display the View ListView manage by ListAdapter Spinner manage by SpinnerAdapter Layouts match_parent - Occupy all the available space. D eprecated starting in API Level 8   fill_parent - Same asd match_parent but for API Level 8 LinearLayout Arrange all the child elements in one line RelativeLayout TableLayout GridView Menus Is defined in a resource XMLfile   res/menu/file.xml Use it on method OnCreate...Menu(), using the menu inflater Use method on...ItemSelection() to handle the item selection Types Options When user press a button In the method onCreateOptionsMenu() add the code to add the menu defined in res/menu/...

Android - Basic Steps (Fragments) II

Add a Fragment Dinamically The general steps are  While the activity is running can add a fragment to the layout  Get reference to the FragmentManager Begin a FragmentTransaction Add the Fragment  Commit the FragmentTransaction To change the previous application to add fragments dynamically, so: In the MainActivity.java override the onCreate method @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); mTitleArray = getResources().getStringArray(R.array.Titles); mQuoteArray = getResources().getStringArray(R.array.Quotes); setContentView(R.layout.main); FragmentManager fragmentManager = getFragmentManager(); FragmentTransaction fragmentTransaction = fragmentManager .beginTransaction(); fragmentTransaction.add(R.id.title_frame, new TitlesFragment()); fragmentTransaction.add(R.id.quote_frame, mQuoteFragment); fragmentTransaction.commit(); } I...

Android - Basic Steps (Fragments)

Fragments This functionality allows to support multiple UI panes / User behavior at the same time A fragment is part of an Activity Multiple Fragments can be embedded in an activity to create  a Multi-Pane UI A single fragment can be reused across multiple activities+ Fragment Lyfeclycle States Resumed Is visible in the sunning state Paused Another activity is in the foreground and has focus, containing activity is visible Stopped Fragment is not visible Fragment Lyfeclycle Methods  onAttach() Fragment is created and attached to the activity onCreate() Initialize the fragment onCreateView Fragments set up &returns its user inferface onActivityCreated activity has completed the onCreate() method and the fragment has been installed onStart() when activity become visible onResume Become visible and ready for user interaction onPause activity is visible without the focus onStop activity is no longer visible onDe...