Académique Documents
Professionnel Documents
Culture Documents
Figure 2.1
- To add logical process, open the FirstActivity.java and add the following code:
1
- For the button, you can either declare a void method as follow public void
fnGreet(View vw) :
- Now open the ThreadedActivity.java and find method onCreate(). This method
means upon starting the activity, this method will be executed first. Add the
following code snippet:
2
- Open the activity_threaded_main.xml, (See Figure 2.2 ) add:
1. ImageView (change ID : imgVwProfile)
2. Button (Change ID : btnTakePic, Text: Take Picture!)
3.
Figure 2.2
- For the new button, add onClick: fnTakePic
3
- The code above will execute another Android activity named
ACTION_IMAGE_CAPTURE
- Note that the ACTION_IMAGE_CAPTURE (line 58 -59) activity execute on different
thread
- runOnUiThead(line 61 – 73) is another thread separated from the
ACTION_IMAGE_CAPTURE thread
- startActivityForResult() at line 59 is a method that will trigger another Intent
activity which has similar function as method startActivity()
- The different is that startActivityForResult() will contain data/information from
another activity where you can manipulate by defining onActivityResult()
- Add the following code snippet to onActivityResult() :
Assignment :
1) On the FirstActivity, find the age of the user based on the year born. Display the
age by appending the textview. Sample output: “Helloo and welcome Ramli.
You are 40 years old”.(currentyear from android studio)
2) Create an ImageView at the first activity and pass image that is captured back
to the first activity previously(image dari threaded to firstactivity)