Untitled
Unit 1 – Foundation of Native Android & Java
Prof. Rinkal Sarvaiya
Assistant Professor, Parul Institute of Engineering & Technology- MCA(FITCS)
Introduction & Programming with ESP8266
Content
- 1.1.1 Objectives
- 1.1.2 Introduction
- 1.1.3 Overview of mobile development (Native vs. Cross-Platform)
- 1.1.4 Introduction to Java for Android development
- 1.1.5 Setting up Android Studio
- 1.1.6 Core Android Components
- 1.1.7 Introduction to the Dart programming language
- 1.1.8 Core Flutter Concepts
- 1.1.9 Case studies
1.1.1 Objectives
- After going through this unit, you should be able to:
- Understand key concepts of mobile app development.
- Know the opportunities and challenges of mobile apps.
- Know the content and key protocols of mobile apps.
- Understand the evolution of mobile apps.
1.1.2 Introduction
- Mobile devices such as smartphones and tablets have become the primary means for internet access, surpassing desktop computers.
- Companies are developing apps that function effectively across various mobile devices to connect with a broader user base.
- Mobile applications are critical for businesses as they facilitate quick and easy customer engagement.
- A "mobile-first" strategy emphasizes optimizing apps for mobile devices prior to any other platform considerations.
- Effective mobile applications prioritize factors such as usability, speed, and personalized experiences for users.
1.1.3 Overview of Mobile Development
- Mobile application development can follow two primary approaches:
- Native Development:
- Involves creating apps expressly for a single platform using the platform’s official languages and tools.
- Examples:
- Android: Uses Java or Kotlin within Android Studio.
- iOS: Uses Swift or Objective-C within Xcode.
- Advantages:
- Optimal performance and speed.
- Complete access to device features (e.g., camera, sensors, Bluetooth).
- Smooth and responsive user interface.
- High stability and reliability.
- Limitations:
- Requires separate codebases for Android and iOS.
- Longer development times and increased costs.
- Necessitates platform-specific knowledge.
- Cross-Platform Development:
- Enables developers to write a single codebase to operate on multiple platforms (Android & iOS).
- Popular Frameworks:
- Flutter (Dart)
- React Native (JavaScript)
- Xamarin (C#)
- Advantages:
- Single codebase simplifies development for both platforms.
- Quicker development and reduced costs.
- Near-native performance, particularly with Flutter.
- Simplified maintenance process.
- Limitations:
- Some advanced features might necessitate native code.
- Slightly diminished performance compared to fully native applications.
1.1.4 Introduction to Java for Android Development
- Java remains one of the primary languages utilized for Android application development, recognized for its readability, portability, and robust community support.
- Reasons to Use Java for Android:
- Officially Supported: Java was the original main language for Android, ensuring continual support.
- Platform-Independent: The "Write Once, Run Anywhere" principle facilitates stable application development across platforms.
- Extensive Ecosystem: A rich library ecosystem and abundant support resources are available for Java.
- Strong Object-Oriented Programming (OOP) Language: Java facilitates the modular structuring of Android applications.
Key Java Concepts Used in Android
- Classes and Objects: Android applications incorporate Java classes; features are represented through objects.
- Inheritance: Most Android components (e.g., Activities, Views) are derived from base classes.
- Example:
AppCompatActivityserves as a foundation forMainActivity.
- Example:
- Interfaces: Used for handling events, such as button click events.
- Packages & Imports: Android's built-in packages include
android.widget.*,android.view.*,android.os.*. - Exception Handling: Essential for avoiding app crashes.
- Example Syntax:
java try { } catch(Exception e) { }
- Example Syntax:
1.1.5 Setting Up Android Studio
Step-by-Step Setup
- Download and Install Android Studio:
- Access the official Android Studio website to download the installer for your operating system (Windows, macOS, Linux).
- Run the installer file and choose the Standard installation option.
- The Android SDK will download automatically during setup.
- First-Time Setup Wizard:
- Select the Standard setup for recommended configuration.
- Choose a theme: options include Light or Dracula (Dark).
- Required SDK components will download automatically.
- Configure the Android SDK:
- Navigate to
File → Settings → Appearance & Behavior → System Settings → Android SDK - Ensure the following components are selected:
- Android SDK Platform (latest version).
- Android SDK Platform Tools.
- Android SDK Build Tools.
- Navigate to
- Create Your First Android Project:
- Click on
New Project. - Select a template, with
Empty Activitybeing recommended. - Enter a device name (e.g., Pixel 5).
- Select a system image (e.g., Android 13).
- Click on
- Run the App:
- Initiate the emulator:
Start Virtual Device. - Press
Runin Android Studio. - Ensure Developer Options are enabled and USB Debugging is activated for testing on a physical device.
- Initiate the emulator:
- Updating Android Studio:
- Check for updates under the
Helpmenu to maintain optimal performance.
- Check for updates under the
1.1.6 Core Android Components
- Android applications are structured using four principal components:
- Activities:
- Define individual screens in an Android app.
- Examples of Activities include:
- Login Screen
- Home Screen
- Settings Screen
- Each Activity is accompanied by a layout (XML file) and corresponding Java/Kotlin code.
Activity Lifecycle:
- Every Activity traverses various stages from initiation to destruction, termed the Activity Lifecycle.
- Lifecycle Methods and Descriptions:
onCreate(): Invoked when the Activity is initialized (UI and variables are set up).onStart(): Activity gains visibility.onResume(): Activity becomes interactive (user input available).onPause(): Another Activity starts to overlay.onStop(): Activity becomes invisible.onDestroy(): Activity is eliminated from memory.onRestart(): Called pre-restart after a pause.
- Important Lifecycle Flow:
onCreate → onStart → onResume → (Activity Running) → onPause → onStop → onDestroy
AndroidManifest.xml:
- This file acts as the core configuration for an Android application, containing vital information such as:
- Activities: Declares the app's screens for launch by Android.
- Permissions: Specifications of resources required by the app (e.g., Internet, Camera, Storage).
- App Info: Contains details about the application, such as name, icon, theme, and package name.
- Minimum SDK: The minimum version of Android required for the application to operate.
- Components: Including Services, Broadcast Receivers, and Content Providers, ensuring Android understands the app's structure and operation.
- This file acts as the core configuration for an Android application, containing vital information such as:
1.1.7 Introduction to the Dart Programming Language
- Dart is the primary language utilized for Flutter application development.
- Developed by Google, Dart facilitates:
- Rapid application development.
- Clean, readable syntax.
- High performance properties.
- Cross-platform application creation across Android, iOS, Web, and Desktop.
- Key Features of Dart:
- Object-Oriented: All entities in Dart are objects (including functions and integers), utilizing classes, inheritance, and polymorphism.
- Strongly Typed: Adheres to specific data types while accommodating flexible data handling.
- Compiles Ahead of Time (AOT) & Just-In-Time (JIT):
- AOT provides rapid performance for release versions.
- JIT grants quick reload during development via Hot Reload in Flutter.
- Null Safety: Avoids common runtime errors by ensuring variables are not null unless explicitly permitted.
1.1.8 Core Flutter Concepts
Key Flutter Concepts
| Concept | Definition | Features | Syntax/Example |
|---|---|---|---|
| Widget | The fundamental building block of Flutter’s UI. Everything in Flutter is a widget such as Text, Image, or Container | Composable, reusable, mostly immutable | Text("Hello Flutter") |
| StatelessWidget | A widget that doesn't change after it's created; contains no state, thus is static content, making it faster | class MyApp extends StatelessWidget { Widget build(ctx) { return Text("Static"); }} | |
| StatefulWidget | A widget that’s UI can change during runtime, accommodating user interactions and data updates; includes State class and utilizes setState() | class Counter extends StatefulWidget { ... } | |
| State | class _CounterState extends State<Counter> { int c=0; build(ctx)=> ElevatedButton(onPressed:(){ setState(()=>c++); }, child:Text("$c")); } | ||
| Scaffold | Basic layout structure for screens, including AppBar, body, Floating Action Button (FAB), and drawer | Scaffold(appBar: AppBar(title: Text("Home")), body: Text("Hi")) | |
| Navigator | Facilitates navigation between pages/screens in a stack-based format | Navigator.push(context, MaterialPageRoute(builder: (c) => Page2())); |
1.1.9 Case Study 1: Native Android App for College Attendance Management
- Problem Statement: A college aims to develop a mobile app to manage student attendance. Faculty members need to mark attendance, view attendance lists, and generate attendance reports. The application should work offline and feature a straightforward user interface.
- Solution Overview:
- The project team opted for a Native Android approach to enhance offline performance and enable direct control over device capabilities.
- The app is developed using Java, employing OOP principles, with classes designed for
StudentandAttendanceRecord. - Activities & Lifecycle: The primary Activities include:
MainActivity: serves as the dashboard.AttendanceActivity: utilized for marking attendance while ensuring data preservation during screen rotations.- Android Studio Setup: Installed Android Studio, configured the SDK, and created the project.
- Gradle Build System: Integrated dependencies in the
build.gradlefile (e.g., Room database). - AndroidManifest.xml: Declared Activities, necessary permissions (e.g., INTERNET), and the app's formal name.
- Outcome: The resulting application is a stable and efficient Native Android app currently employed by five faculty members for daily attendance management.