

























































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
A practical guide to android application development, covering essential aspects such as setting up the development environment, understanding various components, and designing activities using different layouts. It includes step-by-step instructions for installing android studio, configuring the sdk and avd manager, and creating a hello world application. The document also explains the structure of an android application and demonstrates methods of the activity life cycle, making it a valuable resource for students and developers learning to build mobile applications. It also covers linearlayout, relativelayout, gridview, framelayout, and constraintlayout. Useful for university students and lifelong learners.
Typology: Cheat Sheet
1 / 65
This page cannot be seen from the preview
Don't miss anything!


























































Set-up of Android development environment, managing AVD and understanding its various components. Android development environment: Step 1: Install Android Studio Download Android Studio from the website: https://developer.android.com/studio Run the downloaded installer and follow the installation wizard instructions. During the installation, select the components that we want to install, such as the Android SDK, emulator, and development tools. Step 2: Launch Android Studio After the installation is complete, launch Android Studio. Step 3: Configure SDK and AVD Manager On the Android Studio Welcome screen, click on "Configure" in the bottom-right corner and select "SDK Manager." The SDK Manager allows us to install SDK components, platform versions, and system images for different device configurations. Step 4: Install SDK Platforms and System Images In the SDK Platforms tab, install the Android versions (API levels) that we want to target in our app. For example, Android 11 (API 30). Step 5: Create an AVD (Android Virtual Device) After installing the necessary SDK components, click on "AVD Manager". In the AVD Manager, click "Create Virtual Device." Choose the device type we want to emulate (e.g., Pixel 4) and click "Next." Select a system image for the virtual device and click "Next." Configure the AVD properties (e.g., device orientation, scale, RAM, and storage) and click "Finish" to create the AVD. Step 6: Run the AVD Back in the AVD Manager, click the green "Play" button next to the AVD we created to start the virtual device. The AVD will start up, and the Android system running on the virtual device. Step 7: Use AVD for Testing In Android Studio, open Android project.On the toolbar, select AVD from the device dropdown menu. Click the "Run" button to run app on the selected AVD.
Understanding of Various Components available in Android Application. Android applications are built using various components that interact with each other to provide the desired functionality and user experience. Activities : An activity represents a single screen with a user interface. It is the most fundamental component of an Android app and is responsible for interacting with the user. An application may consist of one or multiple activities. Each activity extends the Activity class and typically corresponds to a specific user interaction. Fragments : Fragments are modular sections of an activity that can be combined and reused across multiple activities. They are useful for creating responsive user interfaces, especially on devices with varying screen sizes. Fragments extend the Fragment class and are managed by activities. Services : A service is a component that runs in the background, independent of any user interface. It performs long-running operations or handles tasks that should continue to execute even when app is not in the foreground. Services can be used to play music, download data, or handle network transactions. Broadcast Receivers : A broadcast receiver is a component that listens for and responds to system- wide broadcasts. These broadcasts can be sent by the Android system or other apps. Broadcast receivers allow your app to respond to events, such as incoming SMS messages, network connectivity changes, or battery status updates. Content Providers : A content provider allows the app to share data with other apps securely. It acts as an interface to access and manage the app's data, which can be stored in a database, file, or any other data source. Content providers enable inter-app data sharing, allowing other apps to read or modify the data based on defined permissions. Intents : Intents are messaging objects used to communicate between components within an app or between different apps. They facilitate starting activities, services, or broadcasting events. Intents can carry data along with them to pass information between components. Layouts : Android uses XML-based layout files to define the user interface of an activity or fragment. These layout files specify how different UI elements are arranged and displayed on the screen. Resources : Android apps use resources such as strings, colors, styles, and images. These resources are kept separately from the code, allowing for easy localization and management.
AIM:- Develop Android Application to demonstrate methods of Activity Life Cycle. MainActivity.java
import android.os.Bundle; import android.app.Activity; import android.view.Menu; import android.widget.Toast; public class MainActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Toast.makeText(MainActivity.this,"onCreate method called",Toast.LENGTH_LONG).show(); } @Override protected void onStart() { super.onStart(); Toast.makeText(MainActivity.this,"onStart method called",Toast.LENGTH_LONG).show(); } @Override protected void onResume() { super.onResume(); Toast.makeText(MainActivity.this,"onResume method called",Toast.LENGTH_LONG).show(); } @Override protected void onRestart() { super.onRestart(); Toast.makeText(MainActivity.this,"onRestart method called",Toast.LENGTH_LONG).show(); }
AIM:- Design Android Activities using LinearLayout, RelativeLayout, GridView, FrameLayout, and ConstraintLayout. LinearLayout: activity_main.xml
GridView: activity_main.xml
AIM:- Design various Activities using different Layouts and available Widgets (TextView, EditText, Button, RadioButton, CheckBox, ImageButton, ToggleButton, TimePicker, DatePicker, ProgressBar, ImageView) to make the user-friendly GUI.
1. MainActivity (Linear Layout with EditText and Button):
3. ThirdActivity (Constraint Layout with TimePicker and DatePicker):
AIM:- Develop code to demonstrate different ways of Handling different events (onClick, onLongClick etc.) over Button, EditText etc. to perform action in Android application at run-time. import android.os.Bundle; import android.app.Activity; import android.view.Menu; import android.view.View; import android.widget.Button; import android.widget.EditText; import android.widget.Toast; public class MainActivity extends Activity { EditText et1; Button b1; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); et1=(EditText)findViewById(R.id.editText1); b1=(Button)findViewById(R.id.button1); b1.setOnClickListener(new View.OnClickListener() { @Override
public void onClick(View arg0) { // TODO Auto-generated method stub String s=et1.getText().toString(); Toast t=Toast.makeText(getApplicationContext(), s, Toast.LENGTH_LONG); t.show(); } }); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.main, menu); return true; } }
android:id="@+id/radioOption2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Option 2" /> MainActivity.java import android.os.Bundle; import android.view.View; import android.widget.CheckBox; import android.widget.CompoundButton; import android.widget.RadioButton; import android.widget.RadioGroup; import android.widget.Toast; import androidx.appcompat.app.AppCompatActivity; public class MainActivity extends AppCompatActivity { private CheckBox checkBox; private RadioButton radioOption1, radioOption2; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); checkBox = findViewById(R.id.checkBox); radioOption1 = findViewById(R.id.radioOption1); radioOption2 = findViewById(R.id.radioOption2);
checkBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { if (isChecked) { showToast("CheckBox is checked!"); } else { showToast("CheckBox is unchecked!"); } } }); RadioGroup radioGroup = findViewById(R.id.radioGroup); radioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() { @Override public void onCheckedChanged(RadioGroup group, int checkedId) { switch (checkedId) { case R.id.radioOption1: showToast("Option 1 is selected!"); break; case R.id.radioOption2: showToast("Option 2 is selected!"); break; } } }); } private void showToast(String message) { Toast.makeText(this, message, Toast.LENGTH_SHORT).show(); } }
public void onClick(View arg0) { // TODO Auto-generated method stub Intent i= new Intent(getApplicationContext(),Second.class); startActivity(i); } }); } } Second.java mport android.os.Bundle; import android.app.Activity; import android.view.Menu; public class Second extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_second); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.second, menu); return true; } }
AIM:- Develop an android application to store data locally using Shared Preferences and access-modify in different activities. Create two activities: MainActivity (Default activity) SettingsActivity Implement the layouts for both activities. activity_main.xml: