Differences

This shows you the differences between two versions of the page.

Link to this comparison view

osp:lectures:lecture-internals [2016/10/16 21:57]
vlad.traista [Practical]
osp:lectures:lecture-internals [2016/11/06 18:47] (current)
laura.gheorghe [Lecture]
Line 9: Line 9:
  
   *{{:​osp:​lectures:​lecture-internals.pdf | Lecture Slides}}   *{{:​osp:​lectures:​lecture-internals.pdf | Lecture Slides}}
 +  *{{:​osp:​lectures:​3.internals_notes.pdf | Lecture Notes}}
  
 {{url>​http://​ocw.cs.pub.ro/​courses/​_media/​osp/​lectures/​lecture-internals.pdf}} {{url>​http://​ocw.cs.pub.ro/​courses/​_media/​osp/​lectures/​lecture-internals.pdf}}
Line 22: Line 23:
 {{:​osp:​media:​lab2.zip|}} {{:​osp:​media:​lab2.zip|}}
  
-=== Task 1 - Launching an Activity ===+=== Task 1 - Launching an Activity ​(3p) ===
  
-Create a new project and add a button to the main activity layout. Get a reference to this button in the onCreate method in MainActivity. Add a new Activity to the project. You can add a new activity ​automatically ​by right clicking on the project and selecting **New > Activity > Blank Activity** from the menu. This will start a wizard similar to the one at application creation.+Create a new project and add a button to the main activity layout. Get a reference to this button in the onCreate method in MainActivity. Add a new Activity to the project. You can automatically ​add a new activity by right clicking on the project and selecting **New > Activity > Blank Activity** from the menu. This will start a wizard similar to the one at application creation.
  
-Back in MainActivity,​ add code to the onClick of the OnClickListener so that the new activity gets started. To start a new Activity you have to create an intent first which will explicitly take two parameters: a Context and the Class of the second activity. A context represents an interface to the current state of the application ​/ object. It allows access to application specific resources and operations such as launching an activity or starting a service. In order to obtain the context you can use a reference to the current instance of the MainActivity class.+Back in MainActivity,​ add code to the onClick of the OnClickListener so that the new activity gets started. To start a new Activity you have to create an intent first which will explicitly take two parameters: a Context and the Class of the second activity. A context represents an interface to the current state of the application. It allows access to application specific resources and operations such as launching an activity or starting a service. In order to obtain the context you can use a reference to the current instance of the MainActivity class.
  
 <​code>​ <​code>​
Line 41: Line 42:
 </​code>​ </​code>​
  
-Before launching the new activity, it must be declared in AndroidManifest.xml file. If you create ​the activity ​manually, you will have to add a similar line to the following one to the manifest file. If you created the activity through the wizard, ​it should have been added automatically.+Before launching the new activity, it must be declared in the AndroidManifest.xml file. If you manually created ​the activity , you will have to add a similar line to the following one to the manifest file. If you created the activity through the wizard, ​the line should have been added automatically.
  
 <​code>​ <​code>​
Line 48: Line 49:
 </​code>​ </​code>​
  
-If you created the Activity manually, ​the onCreate of the second activity make sure you call the onCreate of the super class and use setContentView to the layout of the second activity for which you will have to create an empty layout.+If you created the Activity manually, ​in the onCreate of the second activity make sure you call the onCreate of the super class and use setContentView to the layout of the second activity for which you will have to create an empty layout.
  
 <​code>​ <​code>​
Line 55: Line 56:
 </​code>​ </​code>​
  
-Intents can also contain a dictionary of data (called Intent extras). Add an EditText box to your main activity layout and a TextView to your second activity ​layout. When clicking the button, get the text from the EditText elementadd it to the intent. ​+Intents can also contain a dictionary of data (called Intent extras). Add an EditText box to your main activity layout and a TextView to your second activity ​layout. When clicking the button, get the text from the EditText element ​and add it to the intent. ​
  
 <​code>​ <​code>​
Line 64: Line 65:
  
  
-=== Task 2 - Lists and Adapters ===+=== Task 2 - Lists and Adapters ​(4p) ===
  
 For this task, you will have to unpack the lab archive and copy the three files into the current project. Copy **MyMenuItem.java** and **MenuAdapter.java** in the same directory where the activity files reside. Copy **list_item.xml** in **res/​layout**. For this task, you will have to unpack the lab archive and copy the three files into the current project. Copy **MyMenuItem.java** and **MenuAdapter.java** in the same directory where the activity files reside. Copy **list_item.xml** in **res/​layout**.
Line 99: Line 100:
 </​code>​ </​code>​
  
-=== Task 3 - Data Storage ===+=== Task 3 - Data Storage ​(3p) ===
  
 We want to provide a method for persistently storing menu items within the application,​ while also allowing the user to add new ones. For this, modify the behavior of the first EditText (from the first activity) such that its content will not be sent through the intent to the second activity. We will use it for adding the name of a new item. Add other two EditText elements, one for the description and the other one for the price of new items. Also add a new Button, with the "​Add"​ label. When the user clicks it, we want to take the contents of the three EditText elements and add a new item to a database. The second activity will query this database in order to list available items. We want to provide a method for persistently storing menu items within the application,​ while also allowing the user to add new ones. For this, modify the behavior of the first EditText (from the first activity) such that its content will not be sent through the intent to the second activity. We will use it for adding the name of a new item. Add other two EditText elements, one for the description and the other one for the price of new items. Also add a new Button, with the "​Add"​ label. When the user clicks it, we want to take the contents of the three EditText elements and add a new item to a database. The second activity will query this database in order to list available items.
osp/lectures/lecture-internals.1476644244.txt.gz · Last modified: 2016/10/16 21:57 by vlad.traista
CC Attribution-Share Alike 3.0 Unported
www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0