BCA / B.Tech 78 min read

Android programming important questions in Hindi

Android Programming: महत्वपूर्ण प्रश्न (Exam Special)

Short Answer Questions

  1. Android क्या है?
    Android एक open-source, Linux-based mobile operating system है जिसे Google ने develop किया है। यह smartphones, tablets, smartwatches, और TVs के लिए बनाया गया है।
  2. Activity क्या है?
    Activity app की एक single screen को represent करती है जिसके साथ user interact कर सकता है। यह user interface का fundamental building block है।
  3. Intent क्या है?
    Intent एक messaging object है जिसका उपयोग app components के बीच communication करने के लिए किया जाता है। इसका उपयोग activities को start करने, services launch करने, और broadcast भेजने के लिए होता है।
  4. AndroidManifest.xml file क्या है?
    यह हर Android app की root directory में एक configuration file होती है। यह app के components, permissions, और hardware features के बारे में essential information प्रदान करती है।
  5. Gradle क्या है?
    Gradle एक advanced build system है जिसका उपयोग Android Studio में app को build, test, और package करने के लिए किया जाता है। यह dependencies को manage करता है और build process को automate करता है।
  6. Logcat क्या है?
    Logcat, Android Studio का एक tool है जो system और app द्वारा generate किए गए messages को real-time में दिखाता है। इसका उपयोग debugging के लिए error और logs देखने के लिए किया जाता है।
  7. AVD का पूरा नाम क्या है?
    AVD का पूरा नाम Android Virtual Device है। यह एक emulator configuration है जो आपको computer पर एक specific Android device को simulate करने की अनुमति देता है।
  8. Fragment क्या है?
    Fragment एक activity के UI का एक reusable हिस्सा है। एक activity एक साथ multiple fragments को host कर सकती है, जो tablet UIs के लिए बहुत उपयोगी है।
  9. Service क्या है?
    Service एक application component है जो background में long-running operations perform कर सकता है, बिना किसी user interface के।
  10. Content Provider का क्या उपयोग है?
    Content Provider का उपयोग applications के बीच data share करने के लिए किया जाता है। यह data access को manage करता है और security प्रदान करता है।
  11. Toast क्या है?
    Toast एक छोटा popup message है जो screen पर थोड़ी देर के लिए दिखाई देता है। इसका उपयोग user को simple feedback देने के लिए किया जाता है।
  12. findViewById() method क्या करता है?
    यह method XML layout file में defined एक view को उसकी unique ID के आधार पर find करता है और Java code में उसका reference return करता है।
  13. Layouts क्या हैं?
    Layouts `ViewGroup` होते हैं जो screen पर UI widgets की arrangement को define करते हैं। उदाहरण: LinearLayout, RelativeLayout, ConstraintLayout.
  14. SQLite क्या है?
    SQLite एक lightweight, serverless SQL database engine है जो Android में built-in आता है। इसका उपयोग structured data को store करने के लिए किया जाता है।
  15. APK का पूरा नाम क्या है?
    APK का पूरा नाम Android Package Kit है। यह वह file format है जिसका उपयोग Android OS mobile apps को distribute और install करने के लिए करता है।
  16. `R.java` file क्या है?
    यह Android Studio द्वारा automatically generate की गई एक file है। इसमें `res` directory के सभी resources (जैसे layouts, strings, drawables) के लिए unique integer IDs होती हैं।
  17. ADB का पूरा नाम क्या है?
    ADB का पूरा नाम Android Debug Bridge है। यह एक command-line tool है जो आपको एक device (emulator या physical) के साथ communicate करने की सुविधा देता है।
  18. `setContentView()` का क्या उपयोग है?
    यह method एक activity के UI को set करने के लिए उपयोग किया जाता है। यह XML layout file को inflate करता है और उसे screen पर display करता है।
  19. Explicit Intent और Implicit Intent में क्या अंतर है?
    Explicit Intent का उपयोग app के internal components (जैसे एक activity से दूसरी) को start करने के लिए किया जाता है। Implicit Intent का उपयोग system से किसी action (जैसे email भेजना) को perform करने के लिए कहा जाता है।
  20. ANR क्या है?
    ANR का मतलब "Application Not Responding" है। यह एक dialog होता है जो तब दिखाई देता है जब UI thread लंबे समय (5 seconds से ज़्यादा) के लिए block हो जाता है।

Medium Answer Questions

  1. Activity Lifecycle के मुख्य methods को क्रम में समझाएं।
    Activity Lifecycle के मुख्य methods हैं:
    • onCreate(): जब activity पहली बार बनती है। UI initialize किया जाता है।
    • onStart(): जब activity user को visible होने वाली होती है।
    • onResume(): जब activity foreground में आती है और user interact कर सकता है।
    • onPause(): जब activity focus खो देती है (जैसे कोई dialog आता है)।
    • onStop(): जब activity user को completely invisible हो जाती है।
    • onRestart(): जब stopped activity फिर से start होती है।
    • onDestroy(): जब activity memory से destroy हो रही होती है।
    यह flow सुनिश्चित करता है कि app resources को efficiently manage करती है।
  2. SharedPreferences का उपयोग data save करने के लिए कैसे किया जाता है? Code का एक छोटा सा टुकड़ा दें।
    SharedPreferences का उपयोग simple key-value pairs को save करने के लिए किया जाता है, जो user settings के लिए ideal है। Data save करने के लिए, हम `SharedPreferences.Editor` का उपयोग करते हैं।
    
    // Data Save करना
    SharedPreferences prefs = getSharedPreferences("MyPrefs", MODE_PRIVATE);
    SharedPreferences.Editor editor = prefs.edit();
    editor.putString("username", "Ravi");
    editor.apply();
    
    // Data Load करना
    String name = prefs.getString("username", "DefaultUser");
            
  3. ListView और RecyclerView के बीच मुख्य अंतर क्या हैं?
    • ViewHolder Pattern: RecyclerView में ViewHolder pattern को enforce किया जाता है, जो performance को बेहतर बनाता है। ListView में यह optional है।
    • Layout Manager: RecyclerView में एक LayoutManager होता है जो items को position करता है (जैसे LinearLayoutManager, GridLayoutManager)। ListView केवल vertical list support करता है।
    • Flexibility: RecyclerView item animations और customization के लिए ज़्यादा flexible है।
    Modern development में हमेशा `RecyclerView` का उपयोग किया जाना चाहिए।
  4. Android में permissions को कैसे handle किया जाता है? (Manifest और Runtime)
    Android में दो तरह से permissions handle की जाती हैं:
    • Install-time (Manifest) Permissions: ये normal permissions होती हैं जिन्हें app install करते समय grant कर दिया जाता है। इन्हें `AndroidManifest.xml` में declare किया जाता है, जैसे `android.permission.INTERNET`.
    • Runtime Permissions: ये dangerous permissions होती हैं (जैसे `CAMERA`, `LOCATION`, `SEND_SMS`) जिन्हें user से app चलते समय (at runtime) request करना पड़ता है। यह Android 6.0 (API 23) से शुरू हुआ।
  5. Screen orientation change को handle करने के दो तरीके बताएं।
    1. State Save/Restore (Recommended): `onSaveInstanceState()` method का उपयोग करके data को a `Bundle` में save करें और `onCreate()` में उसे restore करें। यह activity के recreate होने पर data loss को रोकता है।
    2. Configuration Change को Handle करना: `AndroidManifest.xml` में `` tag में `android:configChanges="orientation|screenSize"` add करें। यह activity को recreate होने से रोकता है, लेकिन आपको `onConfigurationChanged()` method में UI changes को manually handle करना पड़ता है।
  6. Fragment Lifecycle के मुख्य methods क्या हैं?
    Fragment Lifecycle activity lifecycle से जुड़ा होता है। इसके मुख्य methods हैं: `onAttach()`, `onCreate()`, `onCreateView()` (layout inflate करने के लिए), `onViewCreated()`, `onStart()`, `onResume()`, `onPause()`, `onStop()`, `onDestroyView()` (view destroy करने के लिए), `onDestroy()`, और `onDetach()`।
  7. SQLiteOpenHelper class का क्या उद्देश्य है? इसके दो मुख्य methods बताएं।
    `SQLiteOpenHelper` class database creation और version management को आसान बनाती है।
    • onCreate(SQLiteDatabase db): यह method तब call होता है जब database पहली बार बनता है। इसका उपयोग tables और initial data create करने के लिए किया जाता है।
    • onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion): यह तब call होता है जब `DATABASE_VERSION` बढ़ता है। इसका उपयोग database schema को update करने (जैसे table alter करना) के लिए किया जाता है।
  8. एक app से email भेजने के लिए Intent का उपयोग कैसे करें?
    Email भेजने के लिए `ACTION_SEND` के साथ एक Implicit Intent का उपयोग किया जाता है। आप `putExtra` का उपयोग करके recipient, subject, और body add करते हैं और type को `"message/rfc822"` set करते हैं ताकि केवल email clients ही इसे handle करें।
    
    Intent intent = new Intent(Intent.ACTION_SEND);
    intent.setType("message/rfc822");
    intent.putExtra(Intent.EXTRA_EMAIL, new String[]{"[email protected]"});
    intent.putExtra(Intent.EXTRA_SUBJECT, "Email Subject");
    intent.putExtra(Intent.EXTRA_TEXT, "Email Body");
    startActivity(Intent.createChooser(intent, "Send Email"));
            
  9. `drawable` और `mipmap` folders के बीच क्या अंतर है?
    • `drawable`: इस folder का उपयोग general graphics (जैसे images, shapes, backgrounds) के लिए किया जाता है।
    • `mipmap`: इस folder का उपयोग विशेष रूप से app launcher icons के लिए किया जाता है। Android system different screen densities के लिए best quality icon pick करने के लिए `mipmap` folder को optimize करता है, भले ही app उस density के लिए resources provide न करे।
  10. Notification Channel क्या है और यह क्यों ज़रूरी है?
    Notification Channels को Android 8.0 (API 26) में introduce किया गया था। यह users को app की different types of notifications को manage करने का control देता है। Developers को हर notification के लिए एक channel define करना होता है (जैसे "Messages", "Updates")। User individual channels को block या customize कर सकता है, जिससे user experience बेहतर होता है।
  11. Internal और External Storage में क्या अंतर है?
    • Internal Storage: यह app का private storage होता है। यहां save किया गया data secure होता है और दूसरी apps उसे access नहीं कर सकतीं। App uninstall होने पर यह data delete हो जाता है।
    • External Storage: यह public/shared storage होता है (जैसे SD card)। यहां save किए गए data को user और दूसरी apps access कर सकती हैं। यह large files (photos, videos) के लिए उपयुक्त है।
  12. `ConstraintLayout` का उपयोग करने के क्या फायदे हैं?
    `ConstraintLayout` एक flexible और powerful layout है। इसके फायदे हैं:
    • Flat View Hierarchy: यह nested layouts की ज़रूरत को कम करता है, जिससे performance बेहतर होती है।
    • Flexible Rules: आप child views को parent या other views के relative में complex rules (constraints) के साथ position कर सकते हैं।
    • Responsive UI: यह different screen sizes के लिए responsive UI बनाना आसान बनाता है।
  13. Context Menu और Options Menu में क्या अंतर है?
    • Options Menu: यह activity का primary menu होता है और Action Bar/Toolbar में दिखाई देता है। यह पूरी screen से related actions (जैसे Settings, Search) के लिए होता है।
    • Context Menu: यह तब दिखाई देता है जब user किसी specific view पर long-press करता है। यह उस particular item से related actions (जैसे Edit, Delete) के लिए होता है।
  14. Service और Thread में क्या अंतर है?
    • Thread: यह UI thread से अलग एक execution path है जिसका उपयोग background task करने के लिए किया जाता है ताकि UI freeze न हो। यह app process का हिस्सा है और app destroy होने पर यह भी kill हो जाता है।
    • Service: यह एक Android component है जो background में चलता है, भले ही app visible न हो। यह UI thread पर ही चलता है (unless आप इसके अंदर एक new thread बनाते हैं) और इसका अपना lifecycle होता है।
  15. WebView का उपयोग बताएं। इसे उपयोग करते समय एक सुरक्षा सावधानी क्या है?
    WebView का उपयोग app के अंदर web pages (HTML, CSS, JS) दिखाने के लिए किया जाता है।

    सुरक्षा सावधानी: By default, JavaScript disabled रहता है। यदि आप `setJavaScriptEnabled(true)` का उपयोग करते हैं, तो आपको सावधान रहना चाहिए कि untrusted web content load न करें, क्योंकि यह Cross-Site Scripting (XSS) जैसी vulnerabilities को expose कर सकता है।

  16. `build.gradle (Project)` और `build.gradle (Module)` में क्या अंतर है?
    • `build.gradle (Project)`: यह top-level build file है। यह project के सभी modules के लिए common configuration (जैसे repositories, gradle plugin versions) define करती है।
    • `build.gradle (Module)`: यह हर individual app module के लिए specific configuration (जैसे `applicationId`, `minSdkVersion`, `targetSdkVersion`, dependencies) define करती है।
  17. `SmsManager` class का क्या उपयोग है?
    `SmsManager` class का उपयोग app से programmatic रूप से SMS messages भेजने के लिए किया जाता है। इसका `sendTextMessage()` method destination address और message body लेता है। इसके लिए `SEND_SMS` permission की आवश्यकता होती है।
  18. `ImageView` में `scaleType` attribute का क्या महत्व है?
    `scaleType` attribute यह control करता है कि image को `ImageView` के size में कैसे fit किया जाएगा। Common values हैं:
    • `fitCenter`: Image को aspect ratio बनाए रखते हुए view के अंदर fit करता है।
    • `centerCrop`: Image को scale करता है ताकि वह view को पूरी तरह fill कर दे, और extra part को crop कर देता है।
    • `centerInside`: Image को view के अंदर center करता है और उसे तभी scale down करता है जब वह view से बड़ी हो।
  19. एक custom adapter बनाने की आवश्यकता क्यों पड़ती है?
    `ArrayAdapter` केवल एक single `TextView` वाले simple lists के लिए अच्छा है। जब आपको complex list item layout (जैसे एक image और दो text fields) की आवश्यकता होती है, तो आपको `BaseAdapter` या `RecyclerView.Adapter` को extend करके एक custom adapter बनाना पड़ता है ताकि आप data को custom layout में map कर सकें।
  20. `AsyncTask` deprecated क्यों है और इसका modern alternative क्या है?
    `AsyncTask` memory leaks और configuration changes पर state loss जैसी समस्याओं के कारण deprecated है। Modern Android development में background tasks के लिए Kotlin Coroutines या Java के लिए Executors और Handlers/LiveData का उपयोग करने की सलाह दी जाती है।

Long Answer Questions

  1. Android Architecture को एक diagram के साथ विस्तार से समझाएं।
    Android Architecture को पांच मुख्य परतों में बांटा गया है:
    • 1. Linux Kernel: यह architecture का base है। यह hardware और software के बीच एक abstraction layer प्रदान करता है। यह core system services जैसे memory management, process management, power management, और device drivers (camera, display, WiFi) को handle करता है।
    • 2. Hardware Abstraction Layer (HAL): यह higher-level Java API framework और device drivers के बीच एक standard interface प्रदान करता है। यह Android को device-specific driver implementations से independent बनाता है।
    • 3. Android Runtime (ART) और Native C/C++ Libraries:
      • ART: Android 5.0 से, ART ने Dalvik VM को replace कर दिया। यह app bytecode को execute करता है। यह Ahead-of-Time (AOT) compilation का उपयोग करता है, जो app performance और battery life को improve करता है।
      • Native Libraries: Android platform कई core features (जैसे graphics, media, database) के लिए C/C++ में लिखी गई native libraries का उपयोग करता है। उदाहरण: SQLite, WebKit, OpenGL ES.
    • 4. Java API Framework: यह वह layer है जिसे developers मुख्य रूप से interact करते हैं। यह feature-rich APIs का set प्रदान करता है जिसका उपयोग high-level tasks के लिए किया जाता है। इसमें शामिल हैं: Activity Manager, Content Providers, Resource Manager, Notification Manager, आदि।
    • 5. System Apps (Applications Layer): यह top layer है। इसमें core system apps (जैसे Phone, Contacts, Browser) और user द्वारा install की गई third-party apps शामिल हैं। ये सभी apps Java API Framework का उपयोग करके बनाए जाते हैं।
  2. Google Play Store पर एक application publish करने की पूरी प्रक्रिया का वर्णन करें।
    Application publish करने की प्रक्रिया में कई steps शामिल हैं:
    1. तैयारी:
      • Finalize Application ID: सुनिश्चित करें कि package name unique और final है।
      • Set Versioning: `build.gradle` में `versionCode` और `versionName` को correctly set करें।
      • Create App Icon: High-resolution app icon बनाएं।
      • Remove Debug Code: `Log` statements और debugging flags को हटा दें।
    2. Signed App Bundle बनाना:
      • Google Play पर upload करने के लिए app को digitally sign करना अनिवार्य है।
      • Android Studio में Build > Generate Signed Bundle / APK... पर जाएं।
      • एक नया Keystore बनाएं (यदि आपके पास नहीं है) और उसे एक strong password से protect करें। इस Keystore को कभी न खोएं।
      • Release build type चुनें और signed Android App Bundle (.aab) file generate करें।
    3. Google Play Console पर Setup:
      • एक Google Developer Account बनाएं ($25 one-time fee)।
      • Play Console में एक नई app बनाएं और app details भरें।
      • Store Listing तैयार करें: एक आकर्षक title, detailed description, high-quality screenshots, और feature graphic add करें।
      • App Bundle Upload करें: Production track में generated .aab file upload करें।
      • Content Rating Questionnaire भरें: अपनी app के लिए age rating प्राप्त करने के लिए survey पूरा करें।
      • Pricing & Distribution Set करें: चुनें कि app free है या paid, और किन देशों में उपलब्ध होगी।
      • Privacy Policy Add करें: यदि आपकी app sensitive data collect करती है, तो एक privacy policy URL प्रदान करना अनिवार्य है।
    4. Review और Release:
      • सब कुछ set होने के बाद, release को review के लिए submit करें।
      • Google की review team आपकी app को policies के लिए check करेगी। Approval के बाद, आपकी app Play Store पर live हो जाएगी।
  3. Activity Lifecycle को एक diagram और हर callback method के लिए code example के साथ विस्तार से समझाएं।
    Activity Lifecycle एक activity के विभिन्न states को manage करता है।
    
    public class MyActivity extends AppCompatActivity {
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
            // UI Initialization, one-time setup
        }
        @Override
        protected void onStart() {
            super.onStart();
            // Activity is about to become visible
        }
        @Override
        protected void onResume() {
            super.onResume();
            // Activity is in the foreground, user can interact
            // Start animations, open camera, etc.
        }
        @Override
        protected void onPause() {
            super.onPause();
            // Another activity is coming into the foreground
            // Save unsaved data, stop animations
        }
        @Override
        protected void onStop() {
            super.onStop();
            // Activity is no longer visible
            // Release resources that are not needed
        }
        @Override
        protected void onRestart() {
            super.onRestart();
            // Activity is restarting from stopped state
        }
        @Override
        protected void onDestroy() {
            super.onDestroy();
            // Activity is being destroyed
            // Final cleanup, release all resources
        }
    }
            
    जब एक activity launch होती है, तो `onCreate() -> onStart() -> onResume()` call होते हैं। जब user app से navigate away करता है, तो `onPause() -> onStop()` call होते हैं। यदि user वापस आता है, तो `onRestart() -> onStart() -> onResume()` call होते हैं। यदि app finish होती है, तो `onPause() -> onStop() -> onDestroy()` call होते हैं।
  4. Android में data persistence के विभिन्न तरीकों की व्याख्या करें।
    Data persistence का मतलब app बंद होने के बाद भी data को save रखना है। Android में इसके मुख्य तरीके हैं:
    • 1. SharedPreferences: इसका उपयोग simple data को private primitive data के key-value pairs में save करने के लिए किया जाता है। यह user settings, flags, या small amounts of data के लिए ideal है। Data XML file के रूप में app के private directory में store होता है।
    • 2. Internal File Storage: इसका उपयोग device की internal memory में files को save करने के लिए किया जाता है। यह data app के लिए private होता है और दूसरी apps इसे access नहीं कर सकतीं। App uninstall होने पर यह data delete हो जाता है। यह unstructured data जैसे text files, JSON, या serialized objects के लिए अच्छा है।
    • 3. External File Storage: इसका उपयोग shared external storage (जैसे SD card) पर files save करने के लिए किया जाता है। यह large files (photos, documents) के लिए उपयुक्त है जिन्हें user या दूसरी apps के साथ share करने की आवश्यकता होती है। इसके लिए storage permissions की आवश्यकता होती है।
    • 4. SQLite Databases: इसका उपयोग large amount of structured data को private database में store करने के लिए किया जाता है। Android SQLite database engine के लिए full support प्रदान करता है। `SQLiteOpenHelper` class database management को आसान बनाती है।
    • 5. Room Persistence Library: यह SQLite के ऊपर एक abstraction layer है। यह compile-time पर SQL queries को verify करता है और boilerplate code को कम करता है, जिससे database के साथ काम करना बहुत आसान और robust हो जाता है। यह modern Android development के लिए recommended approach है।
  5. एक custom layout (जिसमें एक ImageView और दो TextViews हों) के साथ RecyclerView बनाने की प्रक्रिया को step-by-step समझाएं।
    1. Dependency Add करें: `build.gradle (Module)` file में RecyclerView की dependency add करें: `implementation 'androidx.recyclerview:recyclerview:1.2.1'`
    2. Custom Row Layout बनाएं: `res/layout` में एक नई XML file (`list_item.xml`) बनाएं। इसमें एक `ImageView` और दो `TextViews` को `LinearLayout` या `ConstraintLayout` के अंदर design करें।
    3. Model Class बनाएं: एक Java class (`MyItem.java`) बनाएं जो list के एक single item के data को hold करेगी (e.g., an image resource ID and two strings).
    4. Custom Adapter बनाएं:
      • एक नई Java class (`MyAdapter.java`) बनाएं जो `RecyclerView.Adapter` को extend करे।
      • इसके अंदर एक inner class `MyViewHolder` बनाएं जो `RecyclerView.ViewHolder` को extend करे। इस class में, `list_item.xml` के views (ImageView, TextViews) को `findViewById()` से initialize करें।
      • Adapter में तीन methods को override करें:
        • onCreateViewHolder(): `list_item.xml` layout को inflate करें और एक new `MyViewHolder` instance return करें।
        • onBindViewHolder(): `position` के आधार पर data list से data get करें और उसे `MyViewHolder` के views में set करें।
        • getItemCount(): Data list का total size return करें।
    5. Activity में RecyclerView को Setup करें:
      • Activity के XML layout में `` add करें।
      • Java code में, RecyclerView का reference get करें।
      • एक `LinearLayoutManager` बनाएं और उसे RecyclerView पर set करें (`recyclerView.setLayoutManager(...)`)।
      • Data की `ArrayList` बनाएं।
      • अपने custom adapter का instance बनाएं, data list pass करें, और उसे RecyclerView पर set करें (`recyclerView.setAdapter(...)`)।
  6. एक Content Provider बनाने और उसे दूसरी app से consume करने की पूरी प्रक्रिया को समझाएं।

    Provider App में:

    1. Database Setup: एक `SQLiteOpenHelper` class बनाएं जो data को manage करेगी।
    2. ContentProvider Class बनाएं: एक class बनाएं जो `ContentProvider` को extend करे।
      • `onCreate()`: Database helper को initialize करें।
      • `query()`: Database से data fetch करने और एक `Cursor` return करने के लिए logic लिखें।
      • `insert()`, `update()`, `delete()`: Database में data manipulate करने के लिए logic लिखें।
      • `getType()`: Return the MIME type of the data.
    3. Define Authority and URI: Provider के लिए एक unique authority string define करें (e.g., "com.example.provider")। एक content URI बनाएं जो data तक पहुंचने का path हो (e.g., `content://com.example.provider/items`)।
    4. Manifest में Register करें: `AndroidManifest.xml` में `` tag का उपयोग करके provider को register करें। `android:authorities` को set करें और `android:exported="true"` करें ताकि दूसरी apps इसे access कर सकें।

    Consumer App में:

    1. ContentResolver का उपयोग करें: `getContentResolver()` method का उपयोग करके `ContentResolver` का instance प्राप्त करें।
    2. Provider से Data Query करें:
      • Provider के content URI को parse करके एक `Uri` object बनाएं।
      • `contentResolver.query(uri, ...)` method को call करें। यह method Provider App के `query()` method को trigger करेगा।
      • Result एक `Cursor` object में मिलेगा।
    3. Cursor से Data Process करें: `Cursor` object पर iterate करें और column names का उपयोग करके data extract करें, फिर उसे UI में display करें।
  7. Fragments क्या हैं? उनके lifecycle और एक activity के साथ communication करने के तरीकों की व्याख्या करें।
    Fragments एक activity के UI के modular sections होते हैं। इनका अपना lifecycle होता है और ये multiple activities में reuse किए जा सकते हैं।

    Lifecycle: Fragment का lifecycle host activity के lifecycle से closely tied होता है। जब activity pause होती है, तो उसके सभी fragments भी pause होते हैं। मुख्य callbacks हैं: `onAttach()`, `onCreate()`, `onCreateView()`, `onViewCreated()`, `onStart()`, `onResume()`, `onPause()`, `onStop()`, `onDestroyView()`, `onDestroy()`, `onDetach()`.

    Communication के तरीके:

    • Fragment से Activity: Fragment एक interface define कर सकता है और `onAttach()` में host activity को इस interface को implement करने के लिए cast कर सकता है। Fragment फिर interface methods को call करके activity से communicate कर सकता है। यह recommended approach है।
    • Activity से Fragment: Activity `FragmentManager` का उपयोग करके fragment का reference get कर सकती है (`findFragmentById()` या `findFragmentByTag()`) और फिर fragment के public methods को directly call कर सकती है।
    • ViewModel: Modern approach में, एक shared `ViewModel` का उपयोग किया जाता है। Activity और Fragment दोनों same `ViewModel` instance को access करते हैं, जो UI-related data को hold करता है। जब `ViewModel` में data change होता है, तो `LiveData` activity और fragment दोनों को notify करता है।
  8. Android में background processing के तरीकों की व्याख्या करें। Service, IntentService, और WorkManager में क्या अंतर है?
    Background processing UI thread को block किए बिना long-running tasks को execute करने के लिए आवश्यक है।
    • Service: यह background में चलने वाला एक component है। यह by default UI thread पर चलता है, इसलिए long tasks के लिए इसके अंदर एक new thread बनाना पड़ता है। यह app बंद होने के बाद भी चल सकता है।
    • IntentService: यह `Service` का một subclass है जो worker thread पर requests को sequentially handle करता है। हर intent request एक-एक करके process होती है। Task पूरा होने पर यह automatically stop हो जाता है। यह simple background tasks के लिए अच्छा था लेकिन अब deprecated है।
    • WorkManager: यह background work के लिए current recommended solution है। यह deferrable (जो तुरंत नहीं चलना चाहिए) और guaranteed (app restart होने पर भी चलेगा) background tasks को schedule करने के लिए एक flexible library है। यह device की battery life को ध्यान में रखते हुए network availability और charging state जैसे constraints के आधार पर work को intelligently run करता है। यह `AsyncTask`, `IntentService`, और `JobScheduler` का modern replacement है।
  9. Google Maps को एक Android app में integrate करने और user की current location को map पर दिखाने की प्रक्रिया को समझाएं।
    1. Google Cloud Console पर Setup:
      • एक project बनाएं और "Maps SDK for Android" API को enable करें।
      • एक API key generate करें और उसे restrict करें ताकि केवल आपकी app उसे उपयोग कर सके (package name और SHA-1 certificate fingerprint का उपयोग करके)।
    2. Project में Setup:
      • `build.gradle` में `play-services-maps` dependency add करें।
      • `AndroidManifest.xml` में API key, internet permission, और location permissions (`ACCESS_FINE_LOCATION`) add करें।
    3. Map को Display करना:
      • Activity के XML layout में `` tag का उपयोग करके `SupportMapFragment` add करें।
      • Activity को `OnMapReadyCallback` interface implement कराएं।
      • `onCreate()` में, `getMapAsync(this)` call करें।
      • `onMapReady(GoogleMap map)` callback method में, `GoogleMap` object का reference save करें।
    4. Current Location दिखाना:
      • Runtime पर location permission check करें और request करें।
      • Permission grant होने पर, `FusedLocationProviderClient` का उपयोग करके last known location get करें या location updates request करें।
      • Map object पर `mMap.setMyLocationEnabled(true)` call करें। यह map पर एक blue dot और current location पर center करने के लिए एक button add कर देगा।
      • (Optional) Location get होने पर, आप `mMap.moveCamera()` का उपयोग करके map को manually उस location पर animate कर सकते हैं।
  10. एक REST API से JSON data fetch करने और उसे RecyclerView में display करने के high-level steps क्या हैं?
    1. HTTP Library Add करें: `build.gradle` में Retrofit या Volley जैसी networking library की dependency add करें। Retrofit modern development के लिए standard है।
    2. Internet Permission: `AndroidManifest.xml` में internet permission add करें।
    3. Model (POJO) Class बनाएं: JSON response के structure से match करने वाली एक Java class बनाएं। यह JSON को Java objects में parse करने में मदद करेगी (GSON या Moshi library का उपयोग करके)।
    4. Retrofit Setup:
      • एक `Retrofit` instance बनाएं, base URL specify करें, और एक converter factory (जैसे `GsonConverterFactory`) add करें।
      • एक Java interface बनाएं और उसमें API endpoints को define करें (e.g., `@GET("users") Call> getUsers();`)।
    5. Data Fetch करें:
      • Activity या ViewModel में, Retrofit service का instance बनाएं।
      • API call method को call करें। यह एक background thread पर execute होगा।
      • `onResponse()` callback में, successful response (list of users) get करें और उसे RecyclerView adapter के data set में add करें। `adapter.notifyDataSetChanged()` call करें।
      • `onFailure()` callback में, error handle करें।
    6. RecyclerView Setup:
      • UI में एक RecyclerView बनाएं।
      • एक custom adapter और ViewHolder बनाएं जो model class के data को list item layout में display करेगा।
      • Activity में, RecyclerView, adapter, और LayoutManager को setup करें। API से data get होने पर adapter को update करें।