Presentation is loading. Please wait.

Presentation is loading. Please wait.

Activity Android Club 2015. Agenda Hello Android application Application components Activity StartActivity.

Similar presentations


Presentation on theme: "Activity Android Club 2015. Agenda Hello Android application Application components Activity StartActivity."— Presentation transcript:

1 Activity Android Club 2015

2 Agenda Hello Android application Application components Activity StartActivity

3 Hello Android! Let’s create your first app! Toast

4 Discover project structure src res AndroidManifest.xml gradle

5 Practice: create project Create Android project Name: MyProject

6 Practice: src Create another activity rather than MainActivity Name: AnotherActivity

7 Practice: AndroidManifest Make AndroidActivity main. Application should open AnotherActivity on start

8 Practice: gradle compile 'io.realm:realm-android:0.81.1'

9 Application components Activity Service BroadcastReceiver ContentProvider

10 Activity Activity – UI where user can interact with application One purpose

11 TaskBackstack

12 Game Button Back Button Which activity it will be?

13 Lifecycle

14 Example: lifecycle Logging lifecycle methods

15 Practice: lifecycle Find out how many methods will be called in this scenario: 1) Open app 2) Click home button 3)Open app from “Opened apps” 4)Click back button 5)Delete app from “Open apps”

16 How to start activity? startActivity startActivityForResult

17 startActivity Put button Set on click listener Open another activity

18 Practice: startActivity Put button on first activity: “Open third activity” Set on click listener startActivity using intent

19 Example: Pass data using Intent Pass data to another activity

20 Example: startActivityForResult Intent i = new Intent(this, SecondActivity.class); startActivityForResult(i, 1); Intent returnIntent = new Intent(); returnIntent.putExtra("result",result); setResult(RESULT_OK,returnIntent); finish();

21 Example: onActivityResult @override protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (requestCode == 1) { if(resultCode == RESULT_OK){ String result=data.getStringExtra("result"); if (resultCode == RESULT_CANCELED) { //Write your code if there's no result } } }

22 Practice: startActivityForResult Create one activity Create one button on first activity Open second activity when button clicked Second activity has 2 buttons: OKEY, BAD On result: show OKEY or BAD

23 Practice: startActivityForResult + data Create one activity Open second activity from first activity Put EditText to second activity Put button to return edittext’s text

24 Homework: Task 1 Create activity one Create 3 buttons on activity one: Red, Green, Blue Red: open RedActivity (background: red) Green: open GreenActivity (bg: green) Blue: open BlueActivity (bg: blue)

25 Homework: Task 2 Create ActivityOne Put edittext Users enters message and clicks “SEND” button SecondActivity shows message in TextView

26 Homework: Task 3 Create activity one Put one button Button open second activity EditText on SecondActivity User enters name in SecondActivity Show toast in FirstActivity: HELLO [NAME]!

27 Homework: Task 4 Create one activity. It should show counters onCreate():1 onStart():1 onResume():1 onPause():0 onStop():0 onPause():0

28 Questions? No question?

29 Thank you! Thank you very much for your attention!


Download ppt "Activity Android Club 2015. Agenda Hello Android application Application components Activity StartActivity."

Similar presentations


Ads by Google