Docsity

Android Development Fundamentals: Core Concepts & Practical Examples, Exams of Software Development

Toggle sidebar
bg1
Android Development Updated
dp - Correct answer Measurement for pixels
alpha - Correct answer Level of transparency
String - Correct answer Class (not primitive) made of chars
sp - Correct answer text pixel measurement
public - Correct answer java code for accessible across entire application
static - Correct answer Method relates to whole class and not just
instances
void - Correct answer java code for return nothing
gravity - Correct answer How your content aligns in element
extends - Correct answer java code for passing attributes
protected - Correct answer java code for privately accessible to specific
package
println - Correct answer Java code stands for Print Line
AS: create public View class called view that returns nothing > call it with
clickFunction > Log "info" "Button pressed" - Correct answer public void
clickFunction(View view) {
Log.f("Info", "Button Press");
}
Where do you input the function name of a button that responds when
clicked? - Correct answer The onClick property section
AS: find the email ID > edit text - Correct answer EditText email =
(EditText) findViewById(R.id.email);
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12

Partial preview of the text

Download Android Development Fundamentals: Core Concepts & Practical Examples and more Exams Software Development in PDF only on Docsity!

Android Development Updated

dp - Correct answer Measurement for pixels alpha - Correct answer Level of transparency String - Correct answer Class (not primitive) made of chars sp - Correct answer text pixel measurement public - Correct answer java code for accessible across entire application static - Correct answer Method relates to whole class and not just instances void - Correct answer java code for return nothing gravity - Correct answer How your content aligns in element extends - Correct answer java code for passing attributes protected - Correct answer java code for privately accessible to specific package println - Correct answer Java code stands for Print Line AS: create public View class called view that returns nothing > call it with clickFunction > Log "info" "Button pressed" - Correct answer public void clickFunction(View view) { Log.f("Info", "Button Press"); } Where do you input the function name of a button that responds when clicked? - Correct answer The onClick property section AS: find the email ID > edit text - Correct answer EditText email = (EditText) findViewById(R.id.email);

AS: get email ID text > parse to string > log email text - Correct answer Log.i("Info", email.getText().toString()); Toast - Correct answer Java code that prints message to screen. AS: make toast for MainActivity > message "Toast Worked" - Correct answer Toast.makeText(MainActivity.this, "Toast Worked", Toast.LENGTH_LONG).show(); Where do images get stored in Android Studio? - Correct answer The drawable folder ImageView - Correct answer Name of images AS: find image1 ID > ImageView - Correct answer ImageView image = (ImageView) findViewById(R.id.image1); AS: get image2 from drawable > set image resource of image ID as image

  • Correct answer image.setImageResource(R.drawable.image2); AS: get text > parse to string > parse to double - Correct answer Double doubleName= Double.parseDouble(stringName.getText().toString()); AS: parse double ID'd euroAmount as 2 decimal string - Correct answer String.format("%.2f", euroAmount) Java: create class called "HelloWorld" > print "Hello World!" - Correct answer public class HelloWorld { public static void main(String[] args) { System.out.println("Hello World"); } } What are classes in Java? - Correct answer Type of object definition What are methods in Java? - Correct answer A chunk of code that does something What is the main method in Java? - Correct answer A method that runs when Java is executed

System.out.println(listName.toString()); Map - Correct answer Java code that maps a property to an object (or hashes one) Java: store a new map in favorites > put favColor blue > put a favNum 7 > log favColor > remove favNum > log map size - Correct answer Map favorites = new HashMap(); favorites.put("color", "blue"); favorites.put("num", 7); System.out.println(favorites.get("color")); favorites.remove("num"); System.out.println(favorites.size()); Java: tells us number of items in hash - Correct answer map.size(); AS: convert string to integer - Correct answer Integer.parseInt(); AS: solution to Error:Execution failed for task ':app:buildInfoDebugLoader' bug - Correct answer Go to Run > Click clean and rerun Where do you do version control with git and github in AS? - Correct answer Under the VCS tab Java: create if statement > if x is less than 5 > log x is less than 5 > else if x is greater than 5 > log x is greater than 5 - Correct answer if (x < 5) { System.out.println("x is less than 5"); } else { System.out.println("x is greater than 5"); } Java: create a for loop > count by 2s > start at 0 > end at 10 - Correct answer for (x = 0; x <= 10; x += 2) {} Java: create a while loop > count by 1s > start at 0 > end at 10 - Correct answer int x = 0; while (x <= 10) { x++ }

Java: create a for each loop > create a String called name for each index in the family array > log the names - Correct answer for (String name : family) { System.out.println(name); } while loop - Correct answer Loop iterates through an array while a condition is true for loop - Correct answer Loop iterates through an array for a specific set of conditions for each loop - Correct answer Loop iterates through an array and peforms an action on each index How do you make each property in an object a string when creating a list? - Correct answer Use the identifier in front of List on both sides of the equal operator Java: create a list called family > make list contain strings > add 2 family members - Correct answer List family = new ArrayList(); family.add("Tony"); family.add("CJ"); How can you align elements in AS? (4) - Correct answer 1) center of screen

  1. relative to another element
  2. corners
  3. margin away from the above Why can we position elements relatively in AS? - Correct answer Everything is defined in RelativeLayout. Making all elements relative to one another What do you use to sub group elements linearly? (2) - Correct answer horizontal or vertical linear layouts

audio.start(); AS: media player start > stop > pause - Correct answer .start(); .stop(); .pause(); AS: find video view called videoView > set the video path to demo/video > start the video - Correct answer VideoView videoView = (VideoView) findViewById(R.id.videoView); videoView.setVideoPath("android.resource://" + getPackageName() + "/" + R.raw.demo/video); videoView.start(); AS: create new media controller named mediaController for video controls > Set mediaController as the anchor for the video view > set mediaController as the Media Controller for video view - Correct answer MediaController mediaController = new MediaController(this); mediaController.setAnchorView(videoView); videoView.setMediaController(mediaController); AS: Add your own code to a method that already exists - Correct answer @Override AS: call AudioManager called audioManager > get Audio Manager service in context Audio Service > set int max volume to stream music > set int current volume to steam music > set max volume to max > set progress to current volume > set stream volume in onProgressChanged to progress - Correct answer AudioManager audioManager; audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE); int maxVolume = audioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC); int curVolume = audioManager.getStreamVolume(AudioManager.STREAM_MUSIC);

volumeControl.setMax(maxVolume); volumeControl.setProgress(curVolume); audioManager.setStreamVolume(AudioManager.STREAM_MUSIC, progress, 0); AS: get ID name of button clicked - Correct answer Id = view.getResources().getResrouceEntryName(id); AS: get file name for raw file - Correct answer int resourcesId = getResources().getIdentifier(ourId, "raw", "com.joncorrin.basicphrases"); AS: create new Handler > create new Runnable > run a log every second - Correct answer final Handler handler = new Handler(); Runnable run = new Runnable(); @Override public void run() { Log.i("test", "run"); handler.postDelayed(this, 1000); } handler.post(run); AS: create new countdown timer from 10 seconds > Log seconds left every second > Log finished on finish - Correct answer new CountDownTimer(10000, 1000) { public void onTick(long millisecondsUntilDone) { Log.i(String.valueOf(millisecondsUntilDone / 1000), "Left"); } public void onFinish() { Log.i("Done", "Finished"); } }.start(); AS: show textView > hide it - Correct answer textView.setVisibility(View.VISIBLE);

downloadImage.setImageBitmap(myImage); } catch (InterruptedException e) { e.printStackTrace(); } catch (ExecutionException e) { e.printStackTrace(); } Java: Create a string with three names > split strings into array on spaces - Correct answer String string = "Jon Tony CJ"; String[] splitString = string.split(" "); .split(""); - Correct answer Method splits string into an array Java: convert string into a substring for any indexes - Correct answer String river = "Mississippi"; String riverPart = river.subString(2, 5); Java: create a Pattern with regex > use matcher to match Pattern to string > use while loop to print while matcher finds pattern - Correct answer String river = "Mississippi"; Pattern p = Pattern.compile("Mi(.*?)pi"); Matcher m = p.matcher(river); while (m.find()) { System.out.println(m.group(1)); } AS: Create download content from URL class - Correct answer public class DownloadTask extends AsyncTask { @Override protected String doInBackground(String... urls) { String result = ""; URL url; HttpURLConnection urlConnection = null; try { url = new URL(urls[0]); urlConnection = (HttpURLConnection) url.openConnection();

InputStream in = urlConnection.getInputStream(); InputStreamReader reader = new InputStreamReader(in); int data = reader.read(); while (data != -1) { char current = (char) data; result += current; data = reader.read(); } return result; } catch (MalformedURLException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return null; } } AS: Call download content from URL in onCreate - Correct answer DownloadTask task = new DownloadTask(); String result = null; try { result = task.execute("http://url.com").get(); Log.i("Content of URl", result); } catch (InterruptedException e) { e.printStackTrace(); } catch (ExecutionException e) { e.printStackTrace(); } Steps for downloading content from the internet (3) - Correct answer 1- Create download content class 2- Call class in onCreate 3- Set user permissions in AndroidManifest AS: Create random number - Correct answer Random random = new Random(); //Generates number -1 of given (50) randomNumber = random.nextInt(51);

MakrerOptions().position(everest).title("Marker").icon(BitmapDescriptorFact ory.defaultMarker(BitmapDescriptorFactory.HUE_BLUE))); AS: zoom in on everest in map - Correct answer mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(everest, 1)); AS: Set map type to hybrid - Correct answer mMap.setMapType(GoogleMap.MAP_TYPE_HYBRID)); AS: Set user permissions for fine location - Correct answer AS: Create location manager - Correct answer LocationManager locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE); AS: Create location listener - Correct answer LocationListener locationListener = new LocationListener() {creates onLocation changed, statusChanged, onProviderEnabled, onProviderDisabled methods} AS: Check if location permission is granted > if it's not, request it > if it is, update location - Correct answer if (ContextCompat.checkSelf(Permission(this, Manifest.permission.ACESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) { ActivityCompat.requestPermissions(this, new String[] {Manifest.permission.ACCESS_FINE_LOCATION}, 1); } else { locationManager.requestLocationUpdates(LocationManager.GPS_PROVID ER, 0, 0, locationListener); } AS: Listen for updates to location if permission is granted - Correct answer public void onRequestPermissionsResult(...) { super.onRequestPermissionsResult(...); if(grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {

if (ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED) { locationManager.requestLocationUpdate(LocationManager.GPS_PROVID ER, 0, 0, locationListener); }} AS: Request location update on device using a build less than API 23 marshmellow - Correct answer if (Build.VERSION.SDK_INT < 23) { locationManager.requestLocationUpdates(LocationManager.GPS_PROVID ER, 0, 0, locationListener); } AS: get users latitude and longitude as a new location - Correct answer LatLng userLocation = new LatLng(location.getLatitude(), location.getLongitude()); AS: Get users last known location - Correct answer Location lastKnownLocation = LocationManager.getLastKnownLocation(LocationManager.GPS_PROVID ER); LatLng location = new LatLng(lastKnownLocation.getLatitude(), lastKnownLocation.getLongitude()); AS: clear the google map - Correct answer mMap.clear(); AS: Create a new geocoder with users location - Correct answer Geocoder geocoder = new Geocoder(getApplicationContext(), Locale.getDefault()); AS: Create new list for users address - Correct answer List listAddresses = geocoder.getFromLocation(location.getLatitude(), location.getLongitude(), 1); //1 means were getting 1 address

AS: Add new items to menu in xml - Correct answer AS: Link menu to main activity - Correct answer @Override public boolean onCreateoptionsMenu(Menu menu) { MenuInflater menuInflater = getMenuInflater(); menuInflater.inflate(R.menu.main_menu, menu); return super.onCreateOptionsMenu(menu); } AS: log item selected on item selection in menu - Correct answer @Override public boolean onOptionsItemSelected(MenuItem item) { super.onoptionsItemSelected(item); switch (item.getItemId()) { case R.id.settings: Log.i("Menu item", "ItemName"); return true; case R.id.settings: Log.i("Menu item", "ItemName"); return true; default: return false; } } AS: create a yes/no alert - Correct answer new AlertDialog.Builder(this) .setIcon(android.R.drawable.ic_dialog_alert) .setTitle("Are you sure?") .setMessage("Do you want to do this?") .setPositiveButton("Yes", new DialogInterface.onClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i){ Toast ...; } } .setNegativeButton("No", null) .show(); }

AS: Create a new Users SQLite database - Correct answer SQLiteDatabase myDatabase = this.openorCreateDatabase("Users", MODE_PRIVATE, null); AS: Create a users table myDatabase.execSQL("CREATE TABLE IF NOT EXISTS users(name VARCHAR, age INT(3))"); AS: Insert data into Users table myDatabase.execSQL("INSERT INTO users (name, age) VALUES ('Rob', 34)"); AS: Get name data from users database Cursor c = myDatabase.rawQuery("SELECT * FROM users", null); int nameIndex = c.getColumnIndex("name"); c.moveToFirst(); while (c != null) { Log.i('name", c.getString(nameIndex)); c.moveToNext(); } AS: get data from SQLite where age is greater than 18 and name is Jon - Correct answer Cursor c = usersDB.rawQuery("SELECT * FROM users WHERE age > 18 AND name = 'Jon'"), null); AS: get data from SQLite where the name starts has a k and limit it to the first result - Correct answer Cursor c = usersDB.rawQuery("SELECT * FROM users WHERE name LIKE '%k%' LIMIT 1", null); AS: delete 1 Jon user from users database - Correct answer usersDB.execSQL("DELETE FROM users WHERE name = 'Jon' LIMIT 1"); AS: Display get webView > enable Javascript > set web view client > load webView URL - Correct answer //Set internet permissions WebView webView = (WebView) findViewById(R.id.webview); webView.getSettings().setJavaScriptEnabled(true); webView.setWebViewClient(new WebViewClient()); AS: Display html webView data that says hello - Correct answer webView.loadData("hello, "text/html", "UTF-8"); webView.loadUrl("https://www.url.com");