manifest file intents and multiple activities n.
Skip this Video
Loading SlideShow in 5 Seconds..
Manifest File, Intents, and Multiple Activities PowerPoint Presentation
Download Presentation
Manifest File, Intents, and Multiple Activities

Loading in 2 Seconds...

play fullscreen
1 / 21

Manifest File, Intents, and Multiple Activities - PowerPoint PPT Presentation

  • Uploaded on

Manifest File, Intents, and Multiple Activities. Manifest File. Manifest file. AndroidManifest.xml required indicates application information activities (within application tag) Android SDK version activities used within the app services that will be used (Web, phone, etc.) other aspects.

I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
Download Presentation

PowerPoint Slideshow about 'Manifest File, Intents, and Multiple Activities' - della

An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.

- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
manifest file1
Manifest file
  • AndroidManifest.xml
    • required
    • indicates application information
      • activities (within application tag)
      • Android SDK version
      • activities used within the app
      • services that will be used (Web, phone, etc.)
      • other aspects
manifest file application tag
Manifest file – Application tag





android:theme="@style/AppTheme" >



android:label="@string/app_name" >


<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />





android:label="Second Screen" >



manifest file2
Manifest File
  • Exploring the <application> tag
    • android:allowBackup=“true”
      • allows app and data to be backed up with a system restore
    • android:icon=“@drawable/ic_launcher”
      • Icon to display in the drawer
    • android:label="@string/app_name“
      • Name of the icon in the drawer
    • <activity>
      • child of <application>
manifest file3
Manifest File
  • Exploring the <activity> tag
    • android:name=“edu.csci153.MultActivities”
      • Associated .java file
    • android:label=“@string/app_name”
      • Text that appears in title bar when this activity is displayed
    • <intent-filter>
      • child of <activity>
manifest file4
Manifest File
  • Exploring the <intent-filter> tag
    • <action android:name="android.intent.action.MAIN" />
      • Indicates this is the main entry point of the application
    • <category android:name="android.intent.category.LAUNCHER" />
      • Indicates that the activity should be launched
    • Without these lines, the application is started but no activity is presented
      • intent-filters ‘filter’ what an object can do – if there is no action defined within the filter, they implicitly deny that the action can be performed
  • Class within Android
    • android.content.Intent
    • contains information regarding some action to be performed
      • starting the phone dialer
      • starting an activity
      • opening a web page
      • other
intent example
Intent Example
  • Starting the phone dialer (no special permission needed)

Intentintent = new Intent(Intent.ACTION_DIAL, Uri.parse("tel:5551234"));


intent example1
Intent Example
  • Opening a web page
    • Permission in manifest file
      • well over 100 different permissions
        • access internet, bluetooth, vibrate phone, change wall paper, etc.
      • uses-permission tag (child of manifest tag)

<uses-permission android:name="android.permission.INTERNET" />

    • Intent in corresponding java file

Intentintent = new Intent(Intent.ACTION_VIEW, Uri.parse(””));


intent example2
Intent Example
  • Opening an Activity

Intent intent = new Intent(this, Screen2.class);


  • ‘this’ refers to the current activity
  • Screen2.class refers to the class file associated with the new activity to be opened
    • implies a corresponding file exists
    • activity MUST be referenced in the manifest file
  • Methods in the Intent class
    • The intent class has many methods to put or retrieve data
      • useful when one Activity launches another
    • put methods used by current Activity that will instantiate another Activity
    • get methods used by new instantiated Activity
  • put… methods
    • put… allows information to be passed from current Activity to newly instantiated Activity
      • putExtra – simple data types and arrays
          • passing an integer
            • i.putExtra(“Key1”, 17);
              • Key1 – name of the integer to be passed
              • 17 – contents of the integer to be passed
          • passing a String
            • i.putExtra(“Key2”, “Value”);
          • passing an array
            • i.putExtra(“Key3”, new int [] {1, 2, 3});
  • get… methods
    • get… allows information to be retrieved by the newly instantiated Activity
      • get…Extra – datatype must be known
        • getting an integer
          • getIntent().getIntExtra(“Key1”, 0);
          • 2nd argument is default value in case Key1 does not exist, or is not an integer
        • getIntent().getStringExtra(“Key2”);
          • retrieves value associated with Key2
          • if no value, null is returned – no default option
        • getting an array
          • int [] z = getIntent().getIntArrayExtra(”Key3");
          • if no value, null is returned – no default option
  • Helpful hints about Activities
    • Each Activity has:
      • a corresponding .java file
      • at least one corresponding .xml file (may have additional menu file)
    • Each Activity must be referenced in the manifest file
    • The Activity class has a getIntent() method to retrieve the intent that initiated it
    • Each activity has a lifecycle
activity lifecycle methods
Activity lifecycle methods
  • Most important (signatures)
    • protected void onCreate(Bundle savedInstanceState);
      • called when created or phone rotated
    • protected void onPause();
      • called when still visible but focus is lost
    • protected void onResume();
      • called when focus is set AFTER being completely obscured
  • When overriding methods, super class’ version MUST be called
example method
Example method


protected void onResume() {


//Code goes here

//Clear fields, set focus, restart sensor

//listeners, etc.


additional information
Additional information
  • Sending information back
    • When one Activity finishes, activity can be sent back to the Activity that started it as follows:
      • In the original Activity, 2 methods are needed
        • startActivityForResult(Intent data, intrequestCode); must be called to open Activity
          • any non-negative integer can be used for requestCode
        • onActivityResult(intrequestCode, intresultCode, Intent data) must be implemented
          • Called when other Activity exits – just before onResume()
            • requestCode is same code from above
            • resultCode is sent from closing Activity
            • data stores any data that was sent back
additional information1
Additional information
  • Continued from previous slide
    • In the opened Activity, 1 method is needed
      • setResult(intresultCode, Intent data) must be called prior to finish()
        • any integer can be used for resultCode
          • Activity.RESULT_CANCELED
          • Activity.RESULT_OK
          • other
        • data stores any data to be sent back
sample code
Sample Code
  • In original Activity

public void openActivityAndWaitForResults() {

Intent i = new Intent(this, SecondActivity.class);

i.putExtra("StringValue", "Coming to you");

startActivityForResult(i, 1);


protected void onActivityResult(intrequestCode, intresultCode, Intent data) {

Toast.makeText(this, "From second activity: " + requestCode + " " + resultCode + " " +data.getStringExtra("InfoBack"), Toast.LENGTH_LONG).show();


  • In opened Activity

public void closeActivityAndSendInfoBack () {

Intent output = new Intent();

output.putExtra("InfoBack", "Back at you!");

setResult(7, output);