I have one app in the Play Store and which is Arabic to Bangla dictionary. I have noticed for some devices it is throwing an Java.lang.OutOfMemoryError in a function which I have given below. The app is works well on some devices but some specific devices crash due to this exception. The exception showing on the below function. My question is why this type of exception occurs and what is the possible solution for this?
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
// realm = Realm.getDefaultInstance()
// realm.beginTransaction()
// realm.delete(SearchHistories::class.java)
// realm.commitTransaction()
if(isLoggedIn() == null) {
if(checkNetworkConnection()) {
val infoService: InfoService = ServiceBuilder.buildService(InfoService::class.java)
val iRequestCall: Call<Info> = infoService.getInfo()
iRequestCall.enqueue(object : Callback<Info> {
override fun onFailure(call: Call<Info>, t: Throwable) {
Toast.makeText(this@MainActivity, "Something went wrong", Toast.LENGTH_SHORT).show()
}
override fun onResponse(call: Call<Info>, response: Response<Info>) {
if(response.isSuccessful) {
val body = response.body()
realm = Realm.getDefaultInstance()
realm.beginTransaction()
val infos = Infos(
id = body!!.id,
activate_info = body.activate_info,
how_to_use = body.how_to_use,
feature = body.feature,
owner_info = body.owner_info,
contact_info = body.contact_info,
copyright = body.copyright,
created_at = body.created_at,
updated_at = body.updated_at
)
realm.copyToRealmOrUpdate(infos)
realm.commitTransaction()
} else {
Toast.makeText(this@MainActivity, "One api failure detected", Toast.LENGTH_SHORT).show()
}
}
})
}
}
mRunnable = Runnable {
if(isLoggedIn() != null) {
val intent = Intent(this, HomeActivity::class.java)
startActivity(intent)
finish()
} else {
val intent = Intent(this, LoginAcitvity::class.java)
startActivity(intent)
finish()
}
// Toast.makeText(this@MainActivity, "hi", Toast.LENGTH_SHORT).show()
}
mHandler = Handler()
mHandler.postDelayed(mRunnable, 5000)
}
[]