![]() CATEGORIES: BiologyChemistryConstructionCultureEcologyEconomyElectronicsFinanceGeographyHistoryInformaticsLawMathematicsMechanicsMedicineOtherPedagogyPhilosophyPhysicsPolicyPsychologySociologySportTourism |
Create the Second ActivityFigure 1. The new activity wizard in Eclipse. To create a new activity using Eclipse:
Click Finish. If you're using a different IDE or the command line tools, create a new file named DisplayMessageActivity.java in the project's src/ directory, next to the original MainActivity.java file. Open the DisplayMessageActivity.java file. If you used Eclipse to create this activity:
Because the ActionBar APIs are available only on HONEYCOMB (API level 11) and higher, you must add a condition around the getActionBar() method to check the current platform version. Additionally, you must add the @SuppressLint("NewApi") tag to the onCreate() method to avoid lint errors. The DisplayMessageActivity class should now look like this: public class DisplayMessageActivity extends Activity {@SuppressLint("NewApi") // Make sure we're running on Honeycomb or higher to use ActionBar APIs @Override If you used an IDE other than Eclipse, update your DisplayMessageActivity class with the above code. All subclasses of Activity must implement the onCreate() method. The system calls this when creating a new instance of the activity. This method is where you must define the activity layout with the setContentView() method and is where you should perform initial setup for the activity components. Note: If you are using an IDE other than Eclipse, your project does not contain the activity_display_message layout that's requested by setContentView(). That's OK because you will update this method later and won't be using that layout. Date: 2014-12-29; view: 1019
|