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

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:

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.

@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>()
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 ->
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
@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.rohit.healthOn.ui.homeScreen
import android.os.Bundle
import android.os.VibrationEffect
import android.os.Vibrator
import androidx.activity.viewModels
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.isVisible
import androidx.lifecycle.lifecycleScope
import androidx.navigation.NavController
package com.rohit.healthOn.ui.homeScreen
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.rohit.healthOn.data.repo.AuthRepo
import com.rohit.healthOn.data.repo.SleepRepo
import com.rohit.healthOn.data.repo.WaterRepo
import com.rohit.healthOn.util.ERROR_TYPE
import com.rohit.healthOn.util.Resource
import dagger.hilt.android.lifecycle.HiltViewModel
package com.rohit.healthOn.ui.homeScreen.dashboardScreen
import android.os.Bundle
import android.view.View
import androidx.fragment.app.Fragment
import androidx.fragment.app.viewModels
import androidx.lifecycle.lifecycleScope
import com.google.android.material.tabs.TabLayoutMediator
import com.rohit.healthOn.R
import com.rohit.healthOn.databinding.FragmentDashboardBinding
package com.rohit.healthOn.ui.homeScreen.dashboardScreen.sleep
import android.os.Bundle
import android.view.View
import androidx.core.view.isVisible
import androidx.fragment.app.Fragment
import androidx.fragment.app.viewModels
import androidx.lifecycle.lifecycleScope
import com.rohit.healthOn.R
import com.rohit.healthOn.databinding.FragmentSleepDashboardBinding