Theory
Two files you did not write, but must understand
When you created FestConnect, Android Studio generated two files that quietly hold the app together. One tells the operating system what your app is and what it may do. The other lets your Java code find the XML resources you designed.
They are AndroidManifest.xml and R.java. You edit the first often and the second never, but both are exam staples and both explain errors like 'Activity not found' and 'cannot resolve R'.
Theory
A passport and an index
The manifest is your app's passport: it states its identity (package name), lists the places it is allowed to go (permissions), and names its screens so the OS recognises them. R.java is the index at the back of a book: every picture, layout, and label gets a page number (an int id) so any chapter (your Java) can jump straight to it by name.
Theory
What each declares
AndroidManifest.xml (required, at the app root) declares:
- the package name,
- every Activity (an undeclared Activity cannot launch),
- the launcher Activity (the one that opens first),
- permissions the app needs (
uses-permission, e.g. INTERNET), - the app icon, theme, and SDK levels.
R.java is auto-generated (never edit it). It gives each resource an int id, so Java can say R.layout.activity_main, R.id.title, R.string.welcome. It is the bridge from XML resources to code.
Practical
AndroidManifest.xml (trimmed)
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.college.festconnect">
<uses-permission android:name="android.permission.INTERNET" />
<application android:icon="@mipmap/ic_launcher" android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>Think first
Which one makes the app open first?
FestConnect has a MainActivity that should be the first screen shown when the app icon is tapped. Which file marks it as the launcher, and what specific piece marks it?
Show the answer
The AndroidManifest.xml, via the <intent-filter> inside that Activity containing the MAIN action and the LAUNCHER category. Together they tell Android 'this is the entry Activity; put its icon in the launcher and start here'. Remove that intent-filter and the app has no launch icon. R.java is not involved in launching; it only maps resources to ids. The manifest owns the app's structure and entry point.
Quiz
You add a second screen, SettingsActivity, write its Java and layout, but the app crashes with 'Activity not found' when you open it. What did you most likely forget?
- To declare <activity android:name=".SettingsActivity"> in AndroidManifest.xml
- To edit R.java to add the new Activity by hand
- To rename the app package
- To delete AndroidManifest.xml
Show the answer
To declare <activity android:name=".SettingsActivity"> in AndroidManifest.xml
Every Activity must be declared in the manifest; an undeclared one cannot be started, giving 'Activity not found' (A). You never edit R.java by hand, it is generated (B). Renaming the package (C) would break far more, and is unrelated. Deleting the manifest (D) would stop the app entirely. Rule: new Activity, add a manifest entry.
Watch out
Manifest and R traps
1. Undeclared Activity: every screen must have an <activity> entry, or launching it crashes.
2. Editing R.java: it is regenerated on every build, so hand edits vanish and cause errors. If 'R cannot be resolved', the fix is usually a broken resource (bad XML) or a failed build, not editing R.
3. Missing permission: features like internet or camera need a uses-permission in the manifest, or they silently fail.
Theory
Next: XML on its own terms
You have now seen XML three times: the layout, the manifest, and resource files, all angle-bracket markup. Unit 3 steps back to teach XML itself: what makes it well-formed, its declaration and prolog, the single root rule, and case sensitivity. Since Android's layouts and manifest are all XML, mastering it makes every file in your project readable.
Summary
Key takeaways
- AndroidManifest.xml is the app's passport: it declares the package, every Activity, the launcher screen, permissions, and SDK levels.
- The launcher Activity is marked by an intent-filter with the MAIN action and LAUNCHER category.
- An Activity not declared in the manifest cannot launch (a common 'Activity not found' cause).
- R.java is auto-generated (never edit it) and maps each resource to an int id: R.layout, R.id, R.string.
- Permissions (internet, camera) must be declared with uses-permission or the feature fails.
- Memory hook: manifest = passport, R.java = the index at the back of the book.