The discussion forum provides a place for discussions.
Declaring layouts: android
To use Fragment class, it depends on the Android version;
import android.app.Fragment (requires API 11 and above)
import android.support.v4.app.Fragment; (requires API 10 and above)
Application Lifecycle
Activity between states.
Activity Lifecycle |
When app starts the activity;
Sequence onCreate - onStart - onResume
When rotating the device
Sequence onPause - onStop - onDestroy - onCreate - onStart - onResume
Toast
Verify data contents with Toast. Within the fragment to be executed, use;Toast toast = Toast.makeText(getContext(), "you did a click", Toast.LENGTH_SHORT );
toast.show();
Networking
The Uri.Builder helps construct http and https URLs.e.g. 1
Uri.Builder builder= new Uri.Builder(); builder.scheme("http") .authority("api.openweathermap.org") .appendPath("data") .appendPath("2.5") .appendPath("forecast") .appendPath("daily") .appendQueryParameter("q", city) .appendQueryParameter("mode","json") .appendQueryParameter("units","metric") .appendQueryParameter("cnt","7");
e.g. 2
final String FORECAST_BASE_URL="http://api.openweathermap.org/data/2.5/forecast/daily?";
builder= new Uri.Builder(); builder.parse(FORECASE_BASE_URL).buildUpon() .appendQueryParameter("q", param[0]) .appendQueryParameter("mode","json") .appendQueryParameter("units","metric") .appendQueryParameter("cnt","7");Test JSON https://jsonformatter.curiousconcept.com/
Android Permissions
Permissions neededhttps://developer.android.com/reference/android/Manifest.permission.html
Thread
AsyncTask class simplify background thread creation and UI thread synchroization.http://developer.android.com/guide/components/processes-and-threads.html
Getting the sample codes
Using git;git clone https://github.com/udacity/Sunshine-Version-2.git
cd Sunshine-Version-2
// Show all branches
git branch -a
// Show only remote branches
git branch -r
git checkout 1.06_attach_adapter
Open Weather JSON
JSON URL sampleshttp://api.openweathermap.org/data/2.5/weather?q=Port%20Dickson
http://api.openweathermap.org/data/2.5/weather?q=Kuala%20Lumpur&units=metric&cnt=5&mode=json
URL query for Sunshine app
requirements: 1 week, JSON format, city, metric
Geonames JSON site at http://www.geonames.org/export/ws-overview.html
Android Studio 1.4 Keyboard Shortcuts
Ctrl+q View quick documentationCtrl+o List members of a class to populate in source
Shift+F6 Rename class, methods and variables with corrections to all places they are used (refactor)
Ctrl+o Override methods of base class
Ctrl+i Implement methods of base class
GIT references
https://git-scm.com/docs/git-show-branchBackup source files
git archive --format zip --output ../chapter1.zip 1.06_attach_adapter