Courses / Mobile Application Development (CDE-315) – BS CS 5th Semester
Week 5 Theory – Application Development with Windows Mobile; Eclipse; Fragments
Week 5 – Windows Mobile, Eclipse and Fragments · 85 min read · 33 MCQs to check yourself
What happened to Windows Phone? (history and lessons)
Bottom navigation with fragments – Navigation Component in Android Studio
Part A – Application development with Windows Mobile
1. History of Microsoft's mobile platforms
| Platform | Years | Key points |
|---|---|---|
| Windows CE / Pocket PC | 1996–2002 | Embedded OS for PDAs; stylus input |
| Windows Mobile 2003 – 6.5 | 2003–2010 | Smartphones and PDAs with stylus and keypads; apps in C/C++ and .NET Compact Framework (C#, VB.NET) using Visual Studio; Win32-style UI |
| Windows Phone 7 / 7.5 | 2010–2012 | Brand-new touch "Metro" design (Live Tiles); apps in C# with Silverlight or XNA (games); no compatibility with old Windows Mobile apps |
| Windows Phone 8 / 8.1 | 2012–2014 | Windows NT kernel shared with Windows 8; XAML + C#/VB, C++, HTML/JS; Nokia Lumia phones |
| Windows 10 Mobile | 2015–2019 | Universal Windows Platform (UWP) – one app for PC, phone, Xbox, HoloLens |
| End of support | 14 January 2020 | Microsoft stopped updates; the Store for phones closed later |
2. How Windows Phone / Windows 10 Mobile apps were built
- IDE: Visual Studio with the Windows Phone SDK / Windows 10 SDK and the Windows Phone Emulator (needs Hyper-V).
- Languages: C# (most common), VB.NET, C++ and JavaScript.
- UI: XAML (eXtensible Application Markup Language) – an XML-based language to describe pages, similar to Android XML layouts.
- Pattern: MVVM (Model-View-ViewModel) with data binding – Microsoft popularised this pattern, now used on Android too.
- App model:
Pageobjects (like Activities), aFrameto navigate, app lifecycle states Running → Suspended → Terminated. - Package:
.xap(WP7/8) and.appx/.appxbundle(UWP); distributed through the Windows Phone Store / Microsoft Store.
<!-- XAML page with a button (Windows Phone / UWP) -->
<Page x:Class="HelloApp.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<StackPanel Margin="20">
<TextBlock x:Name="Greeting" Text="Hello Windows Phone" FontSize="28"/>
<Button Content="Tap me" Click="Button_Click"/>
</StackPanel>
</Page>
// MainPage.xaml.cs (code-behind)
private void Button_Click(object sender, RoutedEventArgs e)
{
Greeting.Text = "Button tapped!";
}
3. Why Windows Phone failed – lessons for developers
- Late entry (2010) when iOS (2007) and Android (2008) already led.
- "App gap" – few popular apps (Snapchat, many banking apps never arrived) → users did not buy phones → developers did not build apps (a vicious circle).
- Breaking changes – WP7 apps could not upgrade to WP8 devices properly; Windows Mobile 6.5 apps did not run on WP7.
- Low market share (under 3–4 %), weak manufacturer support, Microsoft's Nokia purchase (2014) written off. Lesson: a platform succeeds only with a strong developer ecosystem; choose platforms with users.
4. Microsoft in mobile today
- Builds apps for Android and iOS (Outlook, Teams, Office) instead of its own OS.
- .NET MAUI (successor of Xamarin) – write cross-platform Android, iOS, Windows and macOS apps in C# and XAML with Visual Studio. Your Windows Phone skills (C#, XAML, MVVM) transfer directly to MAUI.
- Windows Subsystem for Android (running Android apps on Windows 11) was discontinued in March 2025.
Part B – Eclipse and Android Studio
5. Eclipse IDE with ADT (history)
- Eclipse is a free, open-source, Java-based IDE (Eclipse Foundation) used for Java, C/C++, PHP etc. through plug-ins.
- From 2009 to 2014 Android apps were built in Eclipse + ADT (Android Development Tools) plug-in, with the SDK Manager, AVD Manager, DDMS (Dalvik Debug Monitor Server) perspective, a basic layout editor and Ant build scripts.
- Google announced Android Studio at Google I/O 2013; version 1.0 was released in December 2014, and official support for Eclipse ADT ended in 2015.
6. Eclipse ADT vs Android Studio
| Feature | Eclipse + ADT (old) | Android Studio (current) |
|---|---|---|
| Base | Eclipse platform | IntelliJ IDEA (JetBrains) |
| Build system | Ant (manual) | Gradle – dependencies, build variants, flavours |
| Layout editor | Basic | Powerful design/blueprint view, ConstraintLayout tools, Layout Inspector |
| Code tools | Basic completion | Smart completion, refactoring, Lint, Kotlin support, AI assistant (Gemini) |
| Emulator | Slow AVD | Fast hardware-accelerated emulator, device mirroring |
| Debugging/profiling | DDMS | Logcat, Profiler (CPU, memory, network, energy), App Inspection |
| Templates | Few | Many (Views, Compose, Wear, TV) |
| Support | Ended 2015 | Official and updated several times a year |
Exam note: If a question asks "Application development with Eclipse", explain the steps: install JDK → install Eclipse → install ADT plug-in → configure the SDK path → create Android Application Project → design XML layout → write Java code → run on an AVD. Then mention that Android Studio replaced it.
Part C – Fragments
7. What is a Fragment?
A Fragment represents a reusable portion of an app's UI with its own layout, its own lifecycle and its own input events, that lives inside an activity (its host). Introduced in Android 3.0 Honeycomb for tablets; today use the AndroidX androidx.fragment.app.Fragment class.
Why fragments?
- Modularity – divide a complex screen into independent pieces (list + details).
- Reusability – the same fragment is used in several activities.
- Adaptive UI – on a phone show one fragment per screen; on a tablet show two side-by-side (master–detail) in the same activity.
- Single-activity architecture – modern apps often have one activity hosting many fragments (with bottom navigation, tabs, Navigation component).
- Bottom navigation, tabs (ViewPager2 + TabLayout), navigation drawers and dialogs (DialogFragment) are built with fragments.
Phone (portrait) Tablet (landscape)
+--------------+ +----------+----------------+
| ListFragment| tap item → | List | Detail |
| | Detail | Fragment| Fragment |
+--------------+ replaces +----------+----------------+
8. Fragment lifecycle
A fragment's lifecycle is tied to its host activity (if the activity is paused, all its fragments are paused).
| Callback | Purpose |
|---|---|
onAttach(context) |
Fragment attached to its host activity |
onCreate() |
Initialise non-UI things (arguments, ViewModel) |
onCreateView(inflater, container, state) |
Inflate and return the fragment's layout |
onViewCreated(view, state) |
Find views / set listeners (view is ready) |
onStart() |
Fragment visible |
onResume() |
Fragment interactive |
onPause() |
Losing focus |
onStop() |
No longer visible |
onDestroyView() |
The view hierarchy is removed (clear view references) |
onDestroy() |
Fragment being destroyed |
onDetach() |
Detached from the activity |
Fragments have two lifecycles: the fragment itself and its view (viewLifecycleOwner) – the view can be destroyed (e.g. when replaced and put on the back stack) while the fragment object survives.
9. Creating a fragment
Layout res/layout/fragment_home.xml – a normal layout file.
Class:
public class HomeFragment extends Fragment {
public HomeFragment() {
super(R.layout.fragment_home); // layout given in the constructor
}
@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
TextView tvTitle = view.findViewById(R.id.tvTitle);
tvTitle.setText("Home");
}
}
(Older style: override onCreateView and return inflater.inflate(R.layout.fragment_home, container, false).)
10. Adding fragments to an activity
(a) Statically in XML with FragmentContainerView:
<androidx.fragment.app.FragmentContainerView
android:id="@+id/fragment_container"
android:name="com.example.app.HomeFragment"
android:layout_width="match_parent"
android:layout_height="match_parent" />
(b) Dynamically at run time with the FragmentManager and a FragmentTransaction:
getSupportFragmentManager().beginTransaction()
.replace(R.id.fragment_container, new ProfileFragment())
.addToBackStack(null) // Back returns to the previous fragment
.commit();
| Transaction method | Effect |
|---|---|
add(container, fragment) |
Adds a fragment on top |
replace(container, fragment) |
Removes existing fragment(s) in the container and adds the new one |
remove(fragment) |
Removes a fragment |
hide() / show() |
Hide/show without destroying |
addToBackStack(name) |
Saves the transaction so Back reverses it |
commit() |
Schedules the transaction |
setReorderingAllowed(true) |
Recommended optimisation |
supportFragmentManager– used inside an activity;childFragmentManager– fragments inside a fragment;parentFragmentManager– the manager the fragment belongs to.
11. Passing data and communication
Arguments (a Bundle) – the correct way to give data to a new fragment (survives recreation):
// creating the fragment and giving it data
DetailFragment f = new DetailFragment();
Bundle args = new Bundle();
args.putInt("id", 42);
f.setArguments(args);
// inside DetailFragment (e.g. in onViewCreated)
int id = requireArguments().getInt("id");
Ways for fragments to communicate (they should not reference each other directly):
- Shared ViewModel – both fragments use
activityViewModels()and observe the same data (recommended). - Fragment Result API –
setFragmentResult("key", bundle)/setFragmentResultListener. - Interface callback to the host activity (older approach).
12. Navigation with fragments
- Bottom Navigation View (
com.google.android.material.bottomnavigation.BottomNavigationView) with amenuresource of 3–5 items; on item selection, replace the fragment in the container (lab 5). - Jetpack Navigation component – a navigation graph (XML) of destinations; a
NavHostFragmenthosts them;findNavController().navigate(R.id.detailFragment); Safe Args passes data type-safely; easy to link with BottomNavigationView usingsetupWithNavController. - ViewPager2 + TabLayout – swipeable tabs, each tab a fragment.
- DialogFragment – dialogs that survive rotation.
Activity vs Fragment
| Activity | Fragment |
|---|---|
| Independent screen, entry point declared in manifest | Part of a screen, must be hosted by an activity |
| Has its own window | Has no window of its own |
| Started by intents | Added by FragmentManager / Navigation |
| Heavier | Lightweight, reusable |
| Lifecycle independent | Lifecycle depends on host activity |
Short and long questions
1. What are the two ways to add a fragment to an activity?
Model answer
Statically in the layout XML using a FragmentContainerView (or the older fragment tag) with android:name set to the fragment class; and dynamically at run time using a FragmentTransaction from supportFragmentManager (add/replace + commit).
2. Write code to replace the fragment in a container with ProfileFragment and allow Back to return.
Model answer
supportFragmentManager.beginTransaction().replace(R.id.fragment_container, ProfileFragment()).addToBackStack(null).commit()
3. How can data be passed to a fragment and between fragments?
Model answer
Initial data is passed through the fragment's arguments Bundle (e.g. arguments = bundleOf("id" to 42) and read with requireArguments()). Fragments communicate through a shared ViewModel scoped to the activity, the Fragment Result API, or an interface implemented by the host activity – never by direct references to each other.
4. Discuss application development for Windows Mobile/Windows Phone. Describe its history, development tools, languages and the reasons for its decline. What is Microsoft's mobile strategy today?
Model answer
History: Windows CE/Pocket PC (1996) led to Windows Mobile 2003–6.5 (stylus-based smartphones; apps in C/C++ and .NET Compact Framework). In 2010 Microsoft launched Windows Phone 7 with the Metro design and Live Tiles (C# with Silverlight or XNA). Windows Phone 8 (2012) moved to the Windows NT kernel and supported XAML with C#/VB, C++ and HTML/JS. Windows 10 Mobile (2015) used the Universal Windows Platform so one app could run on PCs, phones, Xbox and HoloLens. Support ended on 14 January 2020.
Development: Visual Studio with the Windows Phone/Windows SDK and Hyper-V emulator; UI in XAML pages with code-behind in C#; MVVM with data binding; navigation through Frame and Page; lifecycle Running → Suspended → Terminated; packages .xap and .appx distributed via the Windows Phone Store.
Decline: late entry, the app gap (missing popular apps), incompatible platform changes that forced developers to rewrite apps, low market share and weak manufacturer support despite buying Nokia.
Today: Microsoft publishes its apps (Office, Outlook, Teams) on Android and iOS and offers .NET MAUI, the successor of Xamarin, for building cross-platform apps in C# and XAML. The lesson for developers: a mobile platform depends on its app ecosystem.
5. Give three reasons why Windows Phone failed.
Model answer
(1) It entered the market late after iOS and Android dominated. (2) The "app gap" – many popular apps were missing, so users avoided it and developers ignored it. (3) Repeated incompatible platform changes (Windows Mobile → WP7 → WP8 → Windows 10 Mobile) and low market share. Support ended in January 2020.
6. How were Windows Phone applications developed?
Model answer
Using Visual Studio with the Windows Phone (later Windows 10) SDK and emulator; UI pages were described in XAML and logic written in C# (also VB.NET, C++ or JavaScript), often with the MVVM pattern; apps were packaged as .xap/.appx and distributed through the Windows Phone Store.
7. Describe Android application development using Eclipse with the ADT plug-in, and explain why Google replaced it with Android Studio.
Model answer
Eclipse + ADT: developers installed the JDK and Eclipse, added the ADT plug-in, pointed it to the Android SDK, and used the SDK Manager and AVD Manager. They created an "Android Application Project" (package name, minimum SDK, launcher activity), designed XML layouts in a basic graphical editor, wrote Java code, and ran apps on an AVD or device. Debugging used the DDMS perspective (Logcat, threads, heap, file explorer) and builds used Ant scripts.
Replacement: Google announced Android Studio in 2013 (stable December 2014) and ended Eclipse ADT support in 2015 because Android Studio, based on IntelliJ IDEA, offered: a Gradle build system with dependency management, build variants and flavours; a much better layout editor and later ConstraintLayout tools; intelligent code completion, refactoring and Lint checks; first-class Kotlin support; a fast emulator; profilers for CPU, memory, network and energy; templates for phones, Wear, TV and Compose; and continuous official updates. All new Android development is done in Android Studio.
8. Compare Eclipse ADT and Android Studio.
Model answer
Eclipse with the ADT plug-in was the original Android IDE (Ant builds, DDMS, basic layout editor) and its support ended in 2015. Android Studio, based on IntelliJ IDEA, is the official IDE with Gradle builds and variants, a powerful layout editor, Lint, Kotlin support, a fast emulator, profilers and regular updates.
9. What is a fragment? Explain the fragment lifecycle with a diagram and describe how fragments are added, replaced and communicated with. Give code.
Model answer
A fragment is a reusable part of an activity's user interface with its own layout and lifecycle (introduced in Android 3.0, now AndroidX). It allows modular, reusable and adaptive UIs – one fragment per screen on phones, several side by side (master–detail) on tablets – and single-activity apps with bottom navigation, tabs and dialogs.
Lifecycle (draw): onAttach → onCreate → onCreateView (inflate layout) → onViewCreated (find views, set listeners) → onStart → onResume [active] → onPause → onStop → onDestroyView → onDestroy → onDetach. The fragment's lifecycle follows its host activity; the view lifecycle can end (onDestroyView) while the fragment remains on the back stack.
Creating: class HomeFragment : Fragment(R.layout.fragment_home) with code in onViewCreated.
Adding statically: a FragmentContainerView in the activity layout with android:name set to the fragment class.
Adding dynamically:
supportFragmentManager.beginTransaction().replace(R.id.fragment_container, ProfileFragment()).addToBackStack(null).commit(). Transaction methods: add, replace, remove, hide, show, addToBackStack and commit.
Passing data: set arguments = bundleOf("id" to 42) before adding and read with requireArguments().getInt("id").
Communication: a shared ViewModel (activityViewModels()), the Fragment Result API (setFragmentResult/setFragmentResultListener) or an interface implemented by the activity.
Navigation: BottomNavigationView or TabLayout + ViewPager2 swap fragments; the Jetpack Navigation component uses a navigation graph and findNavController().navigate(...).
10. Differentiate between an activity and a fragment.
Model answer
An activity is an independent screen with its own window, declared in the manifest and started with intents; a fragment is a part of a screen without its own window, must be hosted by an activity, is added through the FragmentManager or Navigation component, and its lifecycle depends on the host activity.
11. List the fragment lifecycle methods.
Model answer
onAttach, onCreate, onCreateView, onViewCreated, onStart, onResume, onPause, onStop, onDestroyView, onDestroy and onDetach.
12. What is a fragment? Why are fragments used?
Model answer
A fragment is a modular, reusable portion of an activity's UI with its own layout, lifecycle and input handling. Fragments make UIs modular and reusable, allow adaptive layouts (list and detail side by side on tablets), and support single-activity apps with bottom navigation, tabs and dialogs.
This lesson ends with a quiz of 33 MCQs. Open the lesson on PrepOasis to take it and save your progress.
Previous: Assignment 1 (Weeks 1–4) – "My Department" Multi-Screen App and Platform Report · Next: Week 5 Lab 5 – Bottom Navigation Using Fragments Inside a Single Host Activity
All lessons in Mobile Application Development (CDE-315) – BS CS 5th Semester