Application Components
Android application components wo essential building blocks hote hain jo ek app ko banate hain. Ye components ek dusre se loosely connected hote hain through the application manifest file AndroidManifest.xml, jo har component ko describe karta hai aur batata hai ki kaise wo interact karte hain.
Yahan pe char main components diye gaye hain jo Android application mein use hote hain:
1. Activities
Activity ek single screen ko represent karti hai jisme user interface hota hai. Simple shabdon mein, ek Activity screen par actions perform karti hai, jaise data dikhana aur user interaction ko manage karna. Example ke liye, ek email application mein ek activity ho sakti hai jo naye emails ki list dikhaye, dusri activity ho sakti hai jo email compose karne ka kaam kare, aur teesri activity ho sakti hai jo emails padhne ka kaam kare. Agar ek app mein kai activities hain, to unmein se ek ko main activity ke roop mein define karna zaroori hota hai jab app launch hota hai.
Activity ko Activity
class ka subclass banake implement kiya jata hai, kuch is tarah:
}
2. Services
Service ek aisi component hoti hai jo background mein chalti hai aur long-running operations perform karti hai. Jaise, ek service music play kar sakti hai jab user kisi aur app ka use kar raha ho, ya wo data fetch kar sakti hai network se bina user ke activity ke interaction ko block kiye bina.
Service ko Service
class ka subclass banake implement kiya jata hai, kuch is tarah:
}
3. Broadcast Receivers
Broadcast Receivers wo components hote hain jo system ya dusre applications se aayi hui broadcast messages ka response dete hain. Example ke liye, apps dusre apps ko notify kar sakte hain jab koi data device pe download ho jaye, aur broadcast receiver ye message intercept karke appropriate action lega.
Broadcast receiver ko BroadcastReceiver
class ka subclass banake implement kiya jata hai, aur har message ko ek Intent
object ke roop mein broadcast kiya jata hai:
public void onReceive(Context context, Intent intent) {
// Broadcast message ka response dena
}
}
4. Content Providers
Content Providers wo components hote hain jo ek application se dusre applications ko data provide karte hain jab wo request karte hain. Ye requests ContentResolver
class ke methods ke through handle kiye jate hain. Data file system, database ya kahi aur stored ho sakta hai.
Content provider ko ContentProvider
class ka subclass banake implement kiya jata hai aur ek standard set of APIs implement karna zaroori hota hai jisse dusre apps transactions perform kar sake:
public void onCreate() {
// Content provider ko initialize karna
}
Additional Components
Inke alawa kuch aur components hote hain jo upar diye gaye entities ke logic aur wiring mein madad karte hain. Ye hain:
1. Fragments
Fragments ek portion of user interface ko represent karte hain jo ek Activity mein hota hai. Ye flexible UI designs banane mein madad karte hain, especially tablets aur large-screen devices ke liye.
2. Views
Views wo UI elements hote hain jo screen pe draw hote hain, jaise buttons, lists, forms, etc. Ye wo components hote hain jinke saath users interact karte hain.
3. Layouts
Layouts wo structures hote hain jo screen pe views ka format aur appearance control karte hain. Ye UI elements ko organize karte hain aur unki positioning define karte hain.
4. Intents
Intents messages hote hain jo components ko wire karte hain. Ye allow karte hain ki components jaise activities, services, aur broadcast receivers ek dusre se communicate kar sakein.
5. Resources
Resources wo external elements hote hain jo application mein use hote hain, jaise strings, constants, images, aur doosre media. Ye resources generally app ke res
directory mein stored hote hain.
6. Manifest
Manifest file AndroidManifest.xml application ka configuration file hota hai. Isme application ke baare mein zaroori information hoti hai, jaise components, permissions, aur other configuration settings.