You are on page 1of 15

Activity

Activity
- An activity is the single screen in Android
- It is like window or frame of Java
Activity Lifecycle
Activity Lifecycle methods
Activity Implement
- Create an Activity.

class ExampleActivity: AppCompatActivity(){

}
Activity
Activity Implement
- Declaring the activity in the manifest.

- Declaring the activity as a launch screen


INTENT
● Explicit Intent
● Implicit Intent
Activity Implement
- Start another Activity

- LoginActivity.this: Current activity


ExampeActivity.class: The activity need to launch
INTENT
● Explicit Intent
val intent = Intent(this,ExampleActivity::class.java)
startActivity(intent)
● Implicit Intent
val intent = Intent()
intent.action=Intent.ACTION_VIEW
intent.data= Uri.parse("http://google.com")
startActivity(intent)
Communicating Between Activities
- Pass data from Activity A to Activity B.

- Get data from Activity A at Activity B.


Communicating Between Activities
- Pass data from Activity A to Activity B and receive a result back, using:

- Activity A starts activity B

- Activity B sends result


Communicating Between Activities
- Pass data from Activity A to Activity B and Receive a result back (cont'd)
- Activity A receives the result back
Exercise
- MainActivity:
- Enter username & password and touch
Login Button to close Main Activity & open
ProfileAcitivity
- Send name to ProfileActivity
- Clear field username & password if the app
get minimized and re-opened
- ProfileActivity:
- Get username and show on screen
- Press Back button to return back to
MainActivity (update logo in MainActivity)
- Press Send Email button to send an email
- Press Choose Logo button to choose an
image to display as logo.
Exercise illustration

You might also like