Week1-2
Week 3:
2.
Both reorientation and back events involve a destroy
a). List the callbacks (lifecycle and other) in sequence that occur
for a reorientation event.
onPause->onSaveInstanceState->onStop->onDestroy->onCreate->onStart->onRestoreInst anceState->onResume
b). List the callbacks (lifecycle and other) in sequence that occur
• •
How could this go wrong?
•codeName “lollipop” supports API 22. This is called Backward Compatibility(New apps which has new features running on old platform versions).
Under what circumstances can it be fixed?
• Using support library, which take newer features on earlier versions of Android and add to the old API levels.
for a back event
onPause->onStop->onDestroy
c). Why is there a difference.
Email: admin@foruedu. com Mobile: 041 6626 066
1
Your Personal Tutor
1. Consider an app compiled against API level 22 on a device running Nougat(API 25).
• This usually works. Why?
• Forward compatibility
•codeName “Nougat” support API 25. This is called
“Forward compatibility”, which means old apps can run on new platform versions. Android applications are generally forward-compatible with new versions of the Android platform, because almost all changes to the framework API are additive.
• How could this go wrong?
• in isolated cases where the application uses a part of
the API that is later removed for some reason.
• Can it be fixed without changing the API level of the app and the device? Explain.
• No, we can’t fall back, only forward.
Consider an app compiled against API 25 on a device running
lollipop(API 22).
Your Personal Tutor
• If you click “back” button, it means destroy the event, and do not need this event any more.
• However, for the reorientation event, the system knows you still need the event, so it will save all the data, and then destroy the event, then restart the event and get the data from bundle.
3. When does an inherited callback’s super execute if its
a). Not overridden
If the call back is not overridden, then it will execute the super callback method. (parent class)
b). Overridden
if the callback has been overridden, then the method will run the supers callback. Then it will still run the overridden callback method in the child class.
4. Consider the following statement:
Long highScore = sharedPre.getint(getString(R.string.saved_high_score), someVal);
a). What is someVal?
someVal is the default value to return if null (nothing has been saved with that key)
If saved_high_score is empty or hasn’t been assigned a value, the someVal is the default value that will be returned.
b). What does getString do exactly?
Inside the strings.xml resource file there is a key instantiated (saved_high_score), this key has to be retrieved and the getString method is used to retrieve this value.
c). What role does getString’s return value play as a parameter of the getInt method?
getString gets the String value from the strings.xml which in this case is being used as the key to which the value expected is supposedly bound
5. a). What are SharedPreferences files for?
Used for saving key value pairs into persistent memory, so that it can be recovered later on even if we go through a back event.
b). What’s the difference between what is referenced by the return values of getPreferences() and getSharedPreferences()?
o getSharedPreferences() : Use this if you need multiple preferences files identified by name, which you specify with the first parameter.
o getPreferences(…) : Use this if you need only one preferences file for your Activity. Because this will be the only preferences file for your Activity, you don’t supply a name
Email: admin@foruedu. com Mobile: 041 6626 066
2
6. (final)
Your Personal Tutor
A) if the user presses the back button, the current activity will be removed from the back stack. If there still exists activities in the back stack, then the top one will be seen by users, otherwise home screen will be displayed.
B) A task is a collection of activities that users interact with when performing a certain job
Week4: 7.
Email: admin@foruedu. com Mobile: 041 6626 066
3
a) left 16:left margin 16dp right 8: right margin 8dp top16: top margin 16dp down0:bottom margin 0dp 30:30% bias of the top side 20:20% bias of the left side
b) there’s no space
8. :
Your Personal Tutor
a) How many XML attributes in the displayed XML?
b) What is “parent”?
c) What is the name of the root node?
d) When it is processed what will this XML do? e) What does “@color/colorBG” reference?
Email: admin@foruedu. com Mobile: 041 6626 066
4
Your Personal Tutor
• a) 6 attributes (resource, style and 4 items)
• b) Theme.AppCompat.Light.DarkActionBar
• c) resources
• d) Defining AppTheme by inheriting an appcompat theme and overriding (redefining) the
4 most significant colour styles in that theme with custom colours
• e) colorBG(references color in color resource file)
9. :
• Indicates a size ratio between multiple views, in this situation, it means how much space for that column need to be occupied, and there are just one column here, the layout_weight=1 means it will occupy 100% space.
•1
10.
Email: admin@foruedu. com Mobile: 041 6626 066
5
Your Personal Tutor
A) The difference between Barrier and Guideline is that Barrier’s position is flexible and always based on the size of multiple UI elements contained within it and Guideline’s position is always fixed.
B)Guidelines can be specified in dp from start or end of the screen or they can be a percentage of the width of the screen.
specifying a fixed distance from the left or the top of a layout (layout_constraintGuide_begin) specifying a fixed distance from the right or the bottom of a layout (layout_constraintGuide_end)
specifying a percentage of the width or the height of a layout (layout_constraintGuide_percent)
11.
Email: admin@foruedu. com Mobile: 041 6626 066
6
Your Personal Tutor
A)intent
This method is called when the BroadcastReceiver is receiving an Intent broadcast. During this time you can use the other methods on BroadcastReceiver to view/modify the current result values. This method is always called within the main thread of its process
B)
Intent intent = new Intent(); intent.setAction(“week4.workshop.quiz”); intent.putExtra(“the_key”,”FIT2081″); sendBroadcast(intent);
WEEK5:
Email: admin@foruedu. com Mobile: 041 6626 066
7
12.
Your Personal Tutor
a) Using a function link to onClick method, using the button ID to identify the button and then call an
anonymous OnClickListener to use it
b) adapter.notifyDataSetChanged();
13.
(a) drawer.openDrawer(GravityCompat.END)
Email: admin@foruedu. com Mobile: 041 6626 066
8
(B) call the super.onBackPressed() to perform the default
action (Destroy the activity).
14.
Your Personal Tutor
A) To tell Android you have handled the event and no default handling is required. (b)MenuIterm
Pass the menu item that was selected. We can use it to get the id and identify which item is selected.
(c)
onOptionItemSelected is called when an item in the option menu is selected. onNavigationItemSelected is called when an item in the navigation menu is selected
15.
Email: admin@foruedu. com Mobile: 041 6626 066
9
Your Personal Tutor
a) adapter is a bridge connect text data from data sources. It connects an AdapterView and the underlying data for that view.
b) param1: reference (this) which is to access system services and resources, param2: the layout of each item, param3: a list of items
16. :
a) int id = item.getItemId();
if } }
m1(); m2(); m3();
else else
(id ==
if (id ==
if (id ==
R.id.item1) { R.id.item2) { R.id.item3) {
Email: admin@foruedu. com Mobile: 041 6626 066
10
}
17.
Your Personal Tutor
Snackbar.make(v,”confirm Action”,Snackbar.LENGTH_LONG).setAction(“YES”, new View.OnClickListener() {
public void onClick(View view) { this.isConfirmed=true;
} }).show();
WEEK6: 18.
Email: admin@foruedu. com
Mobile: 041 6626 066
11
Your Personal Tutor
a. The first parameter is the layout to hold the fragment. The second parameter is the fragment which have the details of the item.
b. yes, it must have bundle, because bundles can hold all types of values and save data between landscape layout and portrait layout.
c. Use the COMMIT statement to end your current transaction and make permanent all changes performed in the transaction.
19.
Email: admin@foruedu. com Mobile: 041 6626 066
12
(a)
b.
Your Personal Tutor
onCreateViewHolder-create a new ViewHolder in the recycleLayout and passes it to the
onBindViewHolder to fill its data.
• Activity is an application component that represents a full screen. A fragment is a
portion of user interface in an activity.
• An activity may contain 0 or multiple fragments.
• Fragments can be reused in multiple activities.
• A fragment can’t exist independently. It should be always part of an activity.
• A fragment can be added or removed while the activity (the host) is running.
• A fragment has its own lifecycle events.
Week7:
20.
Email: admin@foruedu. com Mobile: 041 6626 066
13
Your Personal Tutor
Observe the changes of data and update the changes of view.
Each time the function getAllUsers is called, livedata can observe the changes of user data. If there is any changes in the list of user, the livedata can be updated
21.
@Query(“select name from users where age >35”)
22.
a) What is the main purpose of implementing the Content Provider in an Android Application?
b) With respect to content provider -How does delete method serve multiple URIs? Email: admin@foruedu. com Mobile: 041 6626 066
14
Week8:
Your Personal Tutor
a)
• Content provider implement a mechanism for the sharing of data between
applications
• Any application can provide other applications with access to its underlying data
through the implementation of a Content Provider including the ability to add,
remove and query the data b)
In each of query methods The URI is fed to a UriMatcher instance which returns a programmer defined code (100 or 200 in this case) indicating whether a single row (200) or table (100) are involved.
A switch statement is then used to perform the appropriate SQLiteDatabase operation (row or table) or, throw an exception if the content URI is illogical
23. :
a) param1:uri url, which is going to specify the content provider and a piece of data you work on, such as the specific row in a specific table of a specific content provider.
24.
param2: ContentValues values; role: represent the value of the new record
b) ContentResolver resolver = getApplicationContext().getContentResolver();
Email: admin@foruedu. com Mobile: 041 6626 066
15
Your Personal Tutor
• The first parameter String is used to indicate the data type of doInBackground and the input parameter of execute method
• The second parameter Integer indicates the data type of the onProgressUpdate and also the input parameter of publishProgress
• The last one Bitmap indicates
o The output of the doInBackground o The input of the onPostExecute
25.
a) Geocoder. getFromLocation Accept latitude and longitude as an input, and then return a list of address
b) wecanspecifythedatatypeofitsmethodsatruntime,notdesigntime
26.
Email: admin@foruedu. com Mobile: 041 6626 066
16
Your Personal Tutor
a)Any number of String parameters are allowed. An list of string, and undefined number, params is the name of the list.
b) Params will be a list of arguments of the type string. They can be accessed using indexes.
c) doInBackground executes on a background thread immediately after calling execute(…). It is used to do background computation that may take a long time. This method can call publishProgress(Progress…) to publish updates on the UI thread
d) onPostExecute executes on the main UI thread after background computation finishes.
WEEK10 27.
Email: admin@foruedu. com Mobile: 041 6626 066
17
Your Personal Tutor
• If there is a frameLayout at the centre of the screen
• Event.getX() means get the x coordinate from the left edge of the frameLayout
• Event.getRawX() means get the x coordinate from the left edge of the screen
28.
View view= findViewById(R.id.frameid); view.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View view, MotionEvent motionEvent) {
int action=motionEvent.getActionMasked(); switch (action){
case MotionEvent.ACTION_DOWN:
Toast.makeText(getBaseContext(),motionEvent.getX()+”/”+motionEvent.getY(),T oast.LENGTH_LONG).show();
break; }
return true; }
});
29.
Email: admin@foruedu. com Mobile: 041 6626 066
18
Your Personal Tutor
• Use getActionMasked to get the event action and it will return the index associated with pointer actions(0 is Down, 1 is UP, 2 is move).
Email: admin@foruedu. com Mobile: 041 6626 066
19