1
00:00:00,270 --> 00:00:05,860
Hi everyone in this directory all of you are going to go ahead and create another Android application.

2
00:00:05,880 --> 00:00:06,830
So just click on this.

3
00:00:06,870 --> 00:00:12,690
Start in your Android studio project and for the name of our application name as you can see here just

4
00:00:12,690 --> 00:00:14,840
type in here app 50.

5
00:00:15,000 --> 00:00:20,840
OK so let me actually delete this name here app 50 and here click on next.

6
00:00:21,210 --> 00:00:26,970
And here are the minimum STK choose AP is 16 Android 4.1 jelly bean.

7
00:00:27,030 --> 00:00:34,240
And then click on next and here choose empty activity next and he can finish.

8
00:00:34,750 --> 00:00:38,750
So now as you can see our application is actually created.

9
00:00:38,760 --> 00:00:43,950
So let's actually get double click on the rest folder here and then double click on the layout folder

10
00:00:44,400 --> 00:00:48,990
and here's double double click on this activity underline made that example.

11
00:00:48,990 --> 00:00:53,610
So here as you can see this is the user interface of our application here.

12
00:00:53,640 --> 00:00:58,150
So just select this hello world takes you here and then press on delete key on your keyboard.

13
00:00:58,440 --> 00:01:04,230
And now let's say you did write a linearly or two vertical at the center of this relative lay out and

14
00:01:04,230 --> 00:01:10,410
then let's actually find the check box which it has you can see here we have this checkbox component

15
00:01:10,620 --> 00:01:12,510
here inside these widgets folder.

16
00:01:12,510 --> 00:01:18,800
So just select it and put it at the center of this linearly 20 call and double click on it.

17
00:01:18,900 --> 00:01:23,640
So as you can see here the text is new checkbox and the IDs checkbox.

18
00:01:23,760 --> 00:01:29,650
And I think that's enough for this tutorial so you can actually leave it as default.

19
00:01:29,810 --> 00:01:30,340
OK.

20
00:01:30,570 --> 00:01:36,300
So I'll just press enter on your keyboard and now there's actually to go inside is main activity that

21
00:01:36,330 --> 00:01:43,080
double file here and here let's actually declare our checkbox object so here can just type in checkbox

22
00:01:43,860 --> 00:01:46,020
and the name of my checkbox is going to be checkbox.

23
00:01:46,050 --> 00:01:53,520
Assignment operator and here I'm going to recast this object to a checkbox object find view by OED or

24
00:01:53,670 --> 00:01:56,070
that ID that checkbox.

25
00:01:56,290 --> 00:02:02,900
OK so here as you can see I actually created this checkbox object inside my class.

26
00:02:02,940 --> 00:02:03,460
OK.

27
00:02:03,480 --> 00:02:09,810
You can actually do this here inside your class or you can actually only declare your checkbox object

28
00:02:09,810 --> 00:02:14,970
in your class and in an instant sheet your checkbox object inside your uncreate Smurfette.

29
00:02:14,970 --> 00:02:18,610
So here I have just been checkbox here.

30
00:02:18,720 --> 00:02:27,150
Assignment operator and then I can actually cast this object to a checkbox object find view by id odd

31
00:02:27,210 --> 00:02:29,220
that Id dot checkbooks.

32
00:02:29,320 --> 00:02:29,610
OK.

33
00:02:29,620 --> 00:02:33,560
And at the end the end of your statement you need to put a semicolon here.

34
00:02:33,560 --> 00:02:38,300
So now I want to talk about shared preferences in Android.

35
00:02:38,340 --> 00:02:42,540
So first of all let's actually run our project now and see what happens.

36
00:02:42,540 --> 00:02:47,120
So now as you can see our application is running on the emulator here.

37
00:02:47,220 --> 00:02:50,340
So if I click on this checkbox here let's see what happens.

38
00:02:50,610 --> 00:02:53,830
And now as you can see the search box is actually checked.

39
00:02:53,940 --> 00:02:56,160
And if I click on the tick box here again.

40
00:02:56,340 --> 00:02:59,760
Now this checkbox is actually checked off.

41
00:02:59,790 --> 00:03:02,690
Now I haven't actually check check this checkbox here.

42
00:03:02,970 --> 00:03:09,570
And then when I actually click on this back button here soon as I can see the undestroyed if it is actually

43
00:03:09,570 --> 00:03:13,320
called and our application is actually no longer in the memory.

44
00:03:13,470 --> 00:03:20,580
And if we want to actually open our application again here as you can see now as you can see that as

45
00:03:20,580 --> 00:03:25,730
you can see here this check box is actually the checked of in the last time that they actually opened

46
00:03:25,800 --> 00:03:27,150
this application.

47
00:03:27,150 --> 00:03:29,850
I actually checked just this checkbox.

48
00:03:29,850 --> 00:03:30,330
OK.

49
00:03:30,540 --> 00:03:32,880
And I want to actually save this state.

50
00:03:32,940 --> 00:03:39,180
So I want to actually check this checkbox and when I actually click on the back button and the application

51
00:03:39,180 --> 00:03:45,900
is actually destroyed inside our memory when I go back to my application of and I actually open my application

52
00:03:45,930 --> 00:03:46,470
again.

53
00:03:46,610 --> 00:03:49,190
I've gone this state here to be saved.

54
00:03:49,200 --> 00:03:53,340
I want this state to be saved and I want to access that state.

55
00:03:53,340 --> 00:03:54,950
So how I can do that.

56
00:03:55,140 --> 00:03:58,820
And that's the purpose of this tutorial in this tutorial.

57
00:03:58,860 --> 00:04:01,130
Want to talk about shared preferences.

58
00:04:01,350 --> 00:04:06,790
In order to actually save your save the status of your application.

59
00:04:06,810 --> 00:04:13,000
So first of all you need to actually make this checkbox here are listening to the police of the user.

60
00:04:13,000 --> 00:04:20,800
So I can't just type in checkbox that set on checked change listener here.

61
00:04:20,810 --> 00:04:24,130
So inside the practices we need to specify the context.

62
00:04:24,150 --> 00:04:26,610
So here I can just type in main activity that this.

63
00:04:26,640 --> 00:04:27,170
OK.

64
00:04:27,400 --> 00:04:33,530
And now we need to actually implement the compound button that unchecked change to listener interface.

65
00:04:33,630 --> 00:04:40,870
So here at the top after this piece of code here extends app compact activity implements and here the

66
00:04:40,870 --> 00:04:50,870
Kansas IPN compound what of it chapiters see compound button that uncheck change listen and with Capitol

67
00:04:50,890 --> 00:04:54,720
all unchecked change listen.

68
00:04:54,730 --> 00:04:55,310
OK.

69
00:04:55,510 --> 00:04:57,250
So here I have this interface.

70
00:04:57,330 --> 00:05:02,380
So we need to actually implement the abstract Smurfette that is inside of this interface in our main

71
00:05:02,380 --> 00:05:03,450
activity class.

72
00:05:03,490 --> 00:05:11,440
So here I can just type in unchecked chained here as you can see this is that this is the method that

73
00:05:11,440 --> 00:05:16,890
is inside of this interface and we are actually implementing that method in our on main activity class.

74
00:05:16,930 --> 00:05:24,940
So whenever the user clicks on this checkbox here as you can see when the user checks or uncheck this

75
00:05:24,940 --> 00:05:29,220
checkbox here or this effort here unchecked change is going to be called OK.

76
00:05:29,470 --> 00:05:36,100
So now as you can see I can just type in if it is checked and this means that if this checkbox here

77
00:05:36,100 --> 00:05:37,370
is actually checked.

78
00:05:37,630 --> 00:05:41,990
So now when I truly create these curly braces here.

79
00:05:42,220 --> 00:05:48,500
So inside these curly braces are you going to actually change this text of this check checkbox here.

80
00:05:48,520 --> 00:05:49,030
OK.

81
00:05:49,210 --> 00:05:57,040
I want to just put the text the checkbox is checked here in in place of this text view takes a view

82
00:05:57,040 --> 00:05:57,830
here OK.

83
00:05:58,060 --> 00:06:04,120
So here I can as you can see I have this checkbox here in my main activity so I can refer to the name

84
00:06:04,120 --> 00:06:11,450
of this checkbox object in my on Cheikh change method so I can just type in checkbox that set text.

85
00:06:11,620 --> 00:06:17,770
And as you can see I can actually change the text of this checkbox then this checkbox is actually checked.

86
00:06:17,890 --> 00:06:23,460
So you say the prentices I can't just put in two double quotes and I can't just type in the checkbox

87
00:06:26,410 --> 00:06:29,970
is checked OK.

88
00:06:30,310 --> 00:06:37,450
And here I actually create an else statement and this means that if this checkbox is actually not checked

89
00:06:37,720 --> 00:06:44,220
ok then I'm going to actually change the text of this text checkbox to this text box is not checked.

90
00:06:44,230 --> 00:06:53,420
So here I can't just refer to the name of this object checkbox that said text and inside Apprentice's

91
00:06:53,680 --> 00:06:56,100
Argento's type in the checkbox

92
00:06:59,130 --> 00:07:02,990
is not checked.

93
00:07:03,090 --> 00:07:10,590
OK so now let's run our project and see what happens when I take or on this checkbooks here.

94
00:07:12,290 --> 00:07:16,190
So as I can say now the application is running on this emulator.

95
00:07:16,280 --> 00:07:18,320
So now I want to check this checkbox.

96
00:07:18,640 --> 00:07:25,760
And as against can heal this checkbox is actually checked and the text of this takes checkbox is actually

97
00:07:26,150 --> 00:07:28,190
the checkbox is checked OK.

98
00:07:28,280 --> 00:07:32,160
So let's actually uncheck this checkbox and that takes these.

99
00:07:32,270 --> 00:07:34,880
The checkbox is not checked OK.

100
00:07:35,300 --> 00:07:39,200
So hopefully that makes sense and want to actually save this state.

101
00:07:39,230 --> 00:07:43,370
For example I can actually check this checkbox over want to save this state in memory.

102
00:07:43,460 --> 00:07:50,240
So when I actually click on dispatch button and the application destroys in memory and when I go back

103
00:07:50,240 --> 00:07:54,890
to my application and open my application I want that state to be saved.

104
00:07:54,920 --> 00:07:55,500
OK.

105
00:07:55,550 --> 00:07:58,840
And as you can see that state is not saved at the moment.

106
00:07:59,060 --> 00:08:01,000
So what's the solution.

107
00:08:01,010 --> 00:08:04,010
The solution is preferences in Android.

108
00:08:04,190 --> 00:08:11,020
So in order to do that first of all we need to actually override the unpause Merfeld on pause Meffert

109
00:08:11,620 --> 00:08:16,660
that is inside of the Android lifecycle on past Meffert and the on resume if.

110
00:08:16,950 --> 00:08:17,460
OK.

