Skip to content

Instantly share code, notes, and snippets.

View rohitjakhar's full-sized avatar
💭
Android Developer

Rohit Jakhar rohitjakhar

💭
Android Developer
View GitHub Profile
@rohitjakhar
rohitjakhar / Intent Flag
Created December 2, 2021 12:47
All flag in Android Intent
FLAG_GRANT_READ_URI_PERMISSION,
FLAG_GRANT_WRITE_URI_PERMISSION,
FLAG_FROM_BACKGROUND,
FLAG_DEBUG_LOG_RESOLUTION,
FLAG_EXCLUDE_STOPPED_PACKAGES,
FLAG_INCLUDE_STOPPED_PACKAGES,
FLAG_GRANT_PERSISTABLE_URI_PERMISSION,
FLAG_GRANT_PREFIX_URI_PERMISSION,
FLAG_DEBUG_TRIAGED_MISSING,
FLAG_IGNORE_EPHEMERAL,
package com.parrychat.android.ui.call
import android.Manifest
import android.annotation.SuppressLint
import android.os.Bundle
import android.util.Log
import android.view.LayoutInflater
import android.view.MotionEvent
import android.view.SurfaceView
import android.view.View
private val onDownloadCompleteReceiver = object : BroadcastReceiver() {
override fun onReceive(context: Context?, intent: Intent?) {
if (intent == null) {
log("onDownloadComplete intent is: $intent")
return
}
if (intent.action == DownloadManager.ACTION_DOWNLOAD_COMPLETE) {
val id = intent.getLongExtra(DownloadManager.EXTRA_DOWNLOAD_ID, -1)
val downloadedFileURI = mDownloadManager?.getUriForDownloadedFile(id)
viewModel.enqueuedDownloadingTasksIds.let { enqueuedTasks ->
@rohitjakhar
rohitjakhar / ExtensionFun.kt
Last active October 4, 2021 14:14
Firebase Realtime Genric Callback
@ExperimentalCoroutinesApi
inline fun <reified T> DatabaseReference.observeValue(): Flow<NetworkResponse<List<T>>> =
callbackFlow {
val listener = object : ValueEventListener {
override fun onCancelled(error: DatabaseError) {
trySend(NetworkResponse.Failure(message = error.message))
}
override fun onDataChange(snapshot: DataSnapshot) {
val hostList = arrayListOf<T>()

Android Interview Questions

Q1: Explain activity lifecycle ☆☆

Answer: As a user navigates through, out of, and back to your app, the Activity instances in your app transition through different states in their lifecycle.

To navigate transitions between stages of the activity lifecycle, the Activity class provides a core set of six callbacks: onCreate(), onStart(), onResume(), onPause(), onStop(), and onDestroy(). The system invokes each of these callbacks as an activity enters a new state.

Interview Questions

Kotlin

Q1: What is a primary constructor in Kotlin? ☆☆

Answer: The primary constructor is part of the class header. Unlike Java, you don't need to declare a constructor in the body of the class. Here's an example:

package com.rohitjakhar.sagarkhurana.viewmodel
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import androidx.paging.Pager
import androidx.paging.PagingConfig
import androidx.paging.cachedIn
import com.google.firebase.auth.ktx.auth
import com.google.firebase.ktx.Firebase
import com.rohitjakhar.sagarkhurana.data.RemoteDataStore
package com.rohitjakhar.sagarkhurana.ui.product
import android.content.Intent
import android.os.Bundle
import android.view.*
import androidx.fragment.app.Fragment
import androidx.fragment.app.viewModels
import androidx.lifecycle.lifecycleScope
import androidx.navigation.fragment.findNavController
import androidx.recyclerview.widget.DividerItemDecoration
val fetechAllData = Pager(PagingConfig(20)) {
ProductPagingSource(db)
}.flow.cachedIn(viewModelScope)
package com.rohitjakhar.sagarkhurana.adapter
import android.util.Log
import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.appcompat.app.AlertDialog
import androidx.core.view.isVisible
import androidx.paging.PagingDataAdapter
import androidx.recyclerview.widget.DiffUtil
import androidx.recyclerview.widget.RecyclerView