0% found this document useful (0 votes)
32 views6 pages

SMD Final Notes

The document compares Firebase Realtime Database and Firestore, highlighting their data models, real-time sync capabilities, offline support, scalability, and querying features. It also discusses when to use SQLite, SharedPreferences, various Android layout types, AppCompatActivity, FirebaseRecyclerView, ListAdapter vs RecyclerView.Adapter, ViewPager and TabLayout, JSON, the Application class, string separation in Java, and converting byte arrays to Bitmaps for use with Picasso. Additionally, it covers the APK format and fragment transactions in Android.

Uploaded by

Rahat Shahid
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
32 views6 pages

SMD Final Notes

The document compares Firebase Realtime Database and Firestore, highlighting their data models, real-time sync capabilities, offline support, scalability, and querying features. It also discusses when to use SQLite, SharedPreferences, various Android layout types, AppCompatActivity, FirebaseRecyclerView, ListAdapter vs RecyclerView.Adapter, ViewPager and TabLayout, JSON, the Application class, string separation in Java, and converting byte arrays to Bitmaps for use with Picasso. Additionally, it covers the APK format and fragment transactions in Android.

Uploaded by

Rahat Shahid
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

Q1: Difference Between Firebase Realtime Database and Firestore

Firebase Realtime Database:

●​ Data Model: Uses a JSON tree.


●​ Real-time Sync: Updates data in real-time across all clients.
●​ Offline Support: Basic offline support.
●​ Scalability: Suitable for small, simple applications. Limited scalability.
●​ Querying: Limited querying capabilities.

Firestore:

●​ Data Model: Uses collections and documents.


●​ Real-time Sync: Also supports real-time updates.
●​ Offline Support: Advanced offline support.
●​ Scalability: Highly scalable with better performance.
●​ Querying: Powerful querying capabilities.

When to Use:

●​ Firebase Realtime Database: Simple, hierarchical data, real-time syncing needed,


small to medium projects.
●​ Firestore: Complex, structured data, better querying, scalability, and offline support
needed, medium to large projects.

Q2: When to Use SQLite

Use SQLite when:

●​ You need a local database to store structured data.


●​ Your application requires complex querying, transactions, or data relationships.
●​ Your app works offline, and data needs to be persistent.
●​ You have a small to medium-sized database.

Q3: SharedPreferences - Advantages and Usage

Advantages:

●​ Easy to use for storing simple key-value pairs.


●​ Good for storing small amounts of data like user settings, preferences, and state
information.
●​ Persistent across app sessions.

When to Use:
●​ Saving user settings and preferences.
●​ Storing simple data like user login status, app theme, etc.

Q4: Layouts in Android and When to Use

●​ LinearLayout: Arranges children in a single direction (vertical/horizontal). Use for simple


layouts.
●​ RelativeLayout: Positions children relative to each other or the parent. Use for more
complex layouts.
●​ ConstraintLayout: More flexible and powerful, reduces nesting. Use for complex, flat
layouts.
●​ FrameLayout: Stacks children on top of each other. Use for overlaying views.
●​ TableLayout: Arranges children into rows and columns. Use for tabular data.
●​ GridLayout: Arranges children in a rectangular grid. Use for grid-like layouts.

Q5: AppCompatActivity

●​ AppCompatActivity: Provides compatibility support for older Android versions.


●​ Use it when you want to maintain backward compatibility and utilize modern Android
features (e.g., action bar, Material Design).

Q6: Why Use FirebaseRecyclerView

●​ Simplifies the process of binding Firebase data to a RecyclerView.


●​ Automatically handles real-time updates from the Firebase database.
●​ Reduces boilerplate code for managing data changes and adapter updates.

Q7: ListAdapter vs RecyclerView.Adapter

●​ ListAdapter: Built-in support for handling data changes and diffing, reduces boilerplate
code.
●​ RecyclerView.Adapter: More flexible and customizable, but you need to handle data
changes manually.

Q8: ViewPager and ViewPager2, TabLayout and TabLayoutMediator

ViewPager:

●​ Allows users to swipe between different fragments or views.


●​ ViewPager2 is the improved version with more features (e.g., vertical scrolling, better
lifecycle handling).

TabLayout and TabLayoutMediator:

●​ TabLayout: Provides a tabbed interface for switching between pages.


●​ TabLayoutMediator: Helps connect a TabLayout with a ViewPager2 to sync tabs with
page changes.

Q9: What is JSON?

●​ JSON (JavaScript Object Notation): A lightweight data-interchange format. Easy to


read and write for humans and machines.
●​ Uses: Data exchange between client and server, configuration files, and more.

Q10: What is the Application Class in Android?

●​ The Application class is the base class for maintaining global application state.
●​ Override it to initialize resources, libraries, and settings that need to be shared across
the app.

Q11: Separate String Based on Token

You can use the split() method in Java to separate a string based on a token

String str = "apple,orange,banana";


String[] parts = str.split(",");
for (String part : parts) {
System.out.println(part);
}

Q1: ByteArray into Bitmap then Load Using Picasso

To convert a byte[] into a Bitmap and then load it using Picasso, follow these steps:

byte[] byteArray = ...; // your byte array


Bitmap bitmap = BitmapFactory.decodeByteArray(byteArray, 0, byteArray.length);

Step 2: Load the Bitmap using Picasso:


ImageView imageView = findViewById(R.id.imageView);
Picasso.get().load(getImageUri(this, bitmap)).into(imageView);

// Helper method to convert Bitmap to Uri


private Uri getImageUri(Context context, Bitmap bitmap) {
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, bytes);
String path = MediaStore.Images.Media.insertImage(context.getContentResolver(), bitmap,
"Title", null);
return Uri.parse(path);
}

Q2: ItemView vs RecyclerView Pros and Cons

●​ ItemView:
○​ Pros: Simple, lightweight, good for individual views.
○​ Cons: Not suitable for handling large lists of data efficiently.
●​ RecyclerView:
○​ Pros: Efficient, supports large datasets, offers features like view recycling,
animations, item decorations.
○​ Cons: More complex setup, requires creating adapters and view holders.

Q3: Why Do We Use FirebaseRecyclerOptions?

●​ FirebaseRecyclerOptions: Provides configuration options for FirebaseRecyclerAdapter.


It helps in binding a Firebase query to a RecyclerView adapter, simplifying the process of
syncing data and handling data changes efficiently.

Q4: Add Icons at the Start of EditText (e.g., Email) and InputEditTextLayout
EditText ... android:drawableLeft="@drawable/my_icon" />

<com.google.android.material.textfield.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:startIconDrawable="@drawable/ic_email">

<com.google.android.material.textfield.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Email" />

</com.google.android.material.textfield.TextInputLayout>

Q5: APK in Android

●​ APK (Android Package): The file format used to distribute and install applications on
Android devices. It contains all the app's code, resources, assets, and manifest.

Q6: Transactions in Fragments (commit, show, hide, etc.)


Fragment transactions allow you to add, replace, remove, show, or hide fragments dynamically
at runtime. Common operations include:

●​ add(): Adds a fragment to a container.


●​ replace(): Replaces an existing fragment.
●​ remove(): Removes a fragment.
●​ show(): Shows a hidden fragment.
●​ hide(): Hides a fragment.
●​ commit(): Commits the transaction.

Q7: ListAdapter vs RecyclerView.Adapter

●​ ListAdapter:
○​ Pros: Built-in support for data changes and diffing.
○​ Cons: Less flexible compared to RecyclerView.Adapter.
●​ RecyclerView.Adapter:
○​ Pros: Highly customizable and flexible.
○​ Cons: Requires more boilerplate code to handle data changes.

Q8: ViewPager and ViewPager2, TabLayout and TabLayoutMediator

●​ ViewPager: Allows users to swipe between fragments or views.


●​ ViewPager2: Improved version of ViewPager, supports vertical scrolling, better
lifecycle handling.
●​ TabLayout: Provides a tabbed interface.
●​ TabLayoutMediator: Connects TabLayout with ViewPager2 to synchronize tabs and
pages.

Q9: What is JSON?

●​ JSON (JavaScript Object Notation): A lightweight data-interchange format that's easy


to read and write for humans and machines. Commonly used for data exchange in web
applications.

Q10: What is the Application Class in Android?

●​ Application Class: Base class for maintaining global application state. Override it to
initialize resources, libraries, and settings shared across the app.

Q11: Separate String Based on Token

You can use the split() method in Java to separate a string based on a token.

String str = "apple,orange,banana";


String[] parts = str.split(",");
for (String part : parts) {
System.out.println(part);
}

You might also like