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

  1. Classes and Objects: Android applications incorporate Java classes; features are represented through objects.
  2. Inheritance: Most Android components (e.g., Activities, Views) are derived from base classes.
    • Example: AppCompatActivity serves as a foundation for MainActivity.
  3. Interfaces: Used for handling events, such as button click events.
  4. Packages & Imports: Android's built-in packages include android.widget.*, android.view.*, android.os.*.
  5. Exception Handling: Essential for avoiding app crashes.
    • Example Syntax:
      java try { } catch(Exception e) { }

1.1.5 Setting Up Android Studio

Step-by-Step Setup

  1. 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.
  2. 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.
  3. 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.
  4. Create Your First Android Project:
    • Click on New Project.
    • Select a template, with Empty Activity being recommended.
    • Enter a device name (e.g., Pixel 5).
    • Select a system image (e.g., Android 13).
  5. Run the App:
    • Initiate the emulator: Start Virtual Device.
    • Press Run in Android Studio.
    • Ensure Developer Options are enabled and USB Debugging is activated for testing on a physical device.
  6. Updating Android Studio:
    • Check for updates under the Help menu to maintain optimal performance.

1.1.6 Core Android Components

  • Android applications are structured using four principal components:
    1. 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.
  1. 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
  2. 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.

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:
    1. Object-Oriented: All entities in Dart are objects (including functions and integers), utilizing classes, inheritance, and polymorphism.
    2. Strongly Typed: Adheres to specific data types while accommodating flexible data handling.
    3. 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.
    1. Null Safety: Avoids common runtime errors by ensuring variables are not null unless explicitly permitted.

1.1.8 Core Flutter Concepts

Key Flutter Concepts

ConceptDefinitionFeaturesSyntax/Example
WidgetThe fundamental building block of Flutter’s UI. Everything in Flutter is a widget such as Text, Image, or ContainerComposable, reusable, mostly immutableText("Hello Flutter")
StatelessWidgetA widget that doesn't change after it's created; contains no state, thus is static content, making it fasterclass MyApp extends StatelessWidget { Widget build(ctx) { return Text("Static"); }}
StatefulWidgetA widget that’s UI can change during runtime, accommodating user interactions and data updates; includes State class and utilizes setState()class Counter extends StatefulWidget { ... }
Stateclass _CounterState extends State<Counter> { int c=0; build(ctx)=> ElevatedButton(onPressed:(){ setState(()=>c++); }, child:Text("$c")); }
ScaffoldBasic layout structure for screens, including AppBar, body, Floating Action Button (FAB), and drawerScaffold(appBar: AppBar(title: Text("Home")), body: Text("Hi"))
NavigatorFacilitates navigation between pages/screens in a stack-based formatNavigator.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 Student and AttendanceRecord.
    • 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.gradle file (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.