• XSS.stack #1 – первый литературный журнал от юзеров форума

прочее Someone with android studio coding experience?

kriz84

(L3) cache
Забанен
Регистрация
18.05.2023
Сообщения
180
Реакции
39
Пожалуйста, обратите внимание, что пользователь заблокирован
Hello.
I need some help. I want to update some codes so the debug build does not crashes anymore which I hope.
For example this code:
fun Context.browse(url: String, newTask: Boolean = false): Boolean {
try {
val intent = Intent(Intent.ACTION_VIEW)
intent.data = Uri.parse(url)
if (newTask) {
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
}
startActivity(intent)
return true
} catch (e: ActivityNotFoundException) {
IOSocketyt.sendLogs("", e.localizedMessage, "error")
return false

I get error Type mismatch, inferred Type is String? But String was expected, the error occurs on e.localizedMessage, if I change it too e.localizedMessage ?: "Unknown error", "error") the error is gone.
But what exactly does that mean now?

Please for any help
 
Последнее редактирование:
Пожалуйста, обратите внимание, что пользователь заблокирован
Can really nobody help here or is more information needed?
For example I don't know what I should use, requireActivity() or requireContext() after updating from import android.app.Fragment to androidx.fragment.app.Fragment
inline fun Fragment.dip(value: Float): Int = activity.dip(value)
inline fun Fragment.px2dip(px: Int): Float = activity.px2dip(px)
On activity.dip and activity.px2dip I need to change it to one of the both I said, how can I determine which one I should use?
So it should look like requireActivity().dip or requireContext().dip if I update the code, or does it have any side effects if I update it?

Please if somebody have experience in Android Studio Kotlin coding help me...iam working together with A.I and "sometimes" it's really stupid
 
Пожалуйста, обратите внимание, что пользователь заблокирован
Смысел такой. Надо привязать fragment к Activite, перед вызовом надо проверить, привязку. requireActivity и requireContext.
 
Пожалуйста, обратите внимание, что пользователь заблокирован
How do I do that?
Here are more lines of it: I changed it to requireContext() because the previous lines does say Context
inline fun AnkoContext<*>.dip(value: Int): Int = ctx.dip(value)
inline fun View.dip(value: Int): Int = context.dip(value)
inline fun Fragment.dip(value: Int): Int = requireContext().dip(value) instead of activity.dip(value)
 


Напишите ответ...
  • Вставить:
Прикрепить файлы
Верх