Android Studio Lab2
Android Studio Lab2
Lab session
Layouts
● Relative Layouts
○ is a layout which arranges views/widgets/viewGroup according to the position
of other views/widgets/viewGroups i.e the new views are placed relative to the
already existing views
○ Most commonly used layout type
…cont’d
…cont’d
…cont’d
…cont’d
Android Activity Lifecycle – has 7 methods
● onCreate() – Called when the activity is first created
● onStart() – Called just after it’s creation or by restart method after onStop(). Here
Activity start becoming visible to user
● onResume() – Called when Activity is visible to user and user can interact with it
● onPause() – Called when Activity content is not visible because user resume previous
activity
● onStop() – Called when activity is not visible to user because some other activity takes
place of it
● onRestart() – Called when user comes on screen or resume the activity which was
stopped
● onDestroy – Called when Activity is not in background
onCreate()
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
onStart(), onRestart()
protected void onStart() {
super.onStart();
}
@Override
protected void onRestart() {
super.onRestart();
}
onPause(), onResume()
protected void onPause() {
super.onPause();