onAttach()
: Bu metod ilk olarak, Fragment’ınız Activity’e içerisinden ilk çağırıldığında çalışır. onCreate () öğesinden bile önce çağırılarak Fragment’ınızın bir Activity’e eklendiğini bildirir.onCreateView()
: Fragment için en önemli metod’dur. Fragment’ın kullanıcı arayüzünü ilk kez çizmek için bu metod çalışır. Layout inflate etmek için bu metodu kullanmanız tavsiye edilir.onViewCreated()
: Bu metod, onCreateView () öğesinden sonra çağrılır.onActivityCreated()
: Bu metod, Activity’nin onCreate () metodunun tamamlandığını belirtmek için onCreate () ve onCreateView () metodlarından sonra çağrılır.onStart()
: Fragment görünür hale geldiğinde(visible olduğunda) onStart () yöntemi çağrılıronPause()
: Uygulama, Fragment’tan ayrıldığında(başka bir uygulamaya geçiş gibi) ilk olarak bu metod çağırılır.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | |
package="com.nisaefendioglu.example"> | |
<application> | |
<activity | |
android:name=".MainActivity" | |
android:exported="true"> | |
<intent-filter> | |
<action android:name="android.intent.action.MAIN" /> | |
</intent-filter> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class InAppUpdate(private val activity: Activity) : InstallStateUpdatedListener { | |
private var appUpdateManager: AppUpdateManager = AppUpdateManagerFactory.create(activity) | |
private val REQUEST_CODE_UPDATE = 500 | |
private var currentUpdateType = AppUpdateType.FLEXIBLE | |
init { | |
// AppUpdateManager örneği oluşturuluyor | |
appUpdateManager.appUpdateInfo.addOnSuccessListener { updateInfo -> | |
if (updateInfo.updateAvailability() == UpdateAvailability.UPDATE_AVAILABLE) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MyPagingActivity : AppCompatActivity() { | |
private val viewModel: MyViewModel by viewModels() | |
private lateinit var adapter: MyPagingDataAdapter | |
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate(savedInstanceState) | |
val binding = ActivityMyPagingBinding.inflate(layoutInflater) | |
setContentView(binding.root) | |
adapter = MyPagingDataAdapter() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MyPagingDataAdapter : PagingDataAdapter<Data, MyPagingDataAdapter.ViewHolder>(diffCallback) { | |
override fun onBindViewHolder(holder: ViewHolder, position: Int) { | |
val data = getItem(position) | |
data?.let { | |
holder.bind(data) | |
} | |
} | |
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder { | |
val layoutInflater = LayoutInflater.from(parent.context) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MyPagingSource(private val apiService: ApiService) : PagingSource<Int, Data>() { | |
override suspend fun load(params: LoadParams<Int>): LoadResult<Int, Data> { | |
try { | |
val pageNumber = params.key ?: 1 | |
val pageSize = params.loadSize | |
val response = apiService.getData(pageNumber, pageSize) | |
val data = response.body() ?: return LoadResult.Error(Exception("Response is null")) | |
val prevKey = if (pageNumber == 1) null else pageNumber - 1 | |
val nextKey = if (data.isEmpty()) null else pageNumber + 1 | |
return LoadResult.Page(data, prevKey, nextKey) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@RunWith(AndroidJUnit4ClassRunner::class) | |
class UserDaoTest { | |
private lateinit var db: TestUserDatabase | |
private lateinit var userDao: UserDao | |
@Before | |
fun createDb() { | |
val context = InstrumentationRegistry.getInstrumentation().targetContext | |
db = Room.inMemoryDatabaseBuilder(context, TestUserDatabase::class.java).build() | |
userDao = db.userDao() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MyPagingSource(private val apiService: ApiService) : PagingSource<Int, Data>() { | |
override suspend fun load(params: LoadParams<Int>): LoadResult<Int, Data> { | |
try { | |
val pageNumber = params.key ?: 1 | |
val pageSize = params.loadSize | |
val response = apiService.getData(pageNumber, pageSize) | |
val data = response.body() ?: return LoadResult.Error(Exception("Response is null")) | |
val prevKey = if (pageNumber == 1) null else pageNumber - 1 | |
val nextKey = if (data.isEmpty()) null else pageNumber + 1 | |
return LoadResult.Page(data, prevKey, nextKey) |
1- var ile val nedir, ne amaçla kullanılır?
- val, değiştirilemeyen yani immutable değişkenler için kullanılır.
- var, değiştirilebilir yani mutable değişkenler için kullanılır.
2- open keyword ne işe yarar?
Kotlin dilinde her şey final’dır, yani değiştirilemez. Bu yüzden kullanılmak istenen sınıfların ve fonksiyonların önüne open keyword yazılmalıdır.
NewerOlder