I am trying to pass data between fragments using navigation controller. in this documentation: https://developer.android.com/topic/libraries/architecture/navigation/navigation-pass-data
it is said that I can send data using bundle, but when I type the code below:
var bundle = bundleOf("amount" to amount)
view.findNavController().navigate(R.id.confirmationAction, bundle)
I have a message: Bundle' is deprecated. Use Android KTX version ?
what should I do ? I don't understand about that 'Use the Android KTX version'
I finally find the answer,
so first add dependecy:
dependencies {
implementation 'androidx.core:core-ktx:1.0.0'
}
then import this:
import androidx.core.os.bundleOf
and finally the warning will dissapear
I think it's requesting that top level function: https://developer.android.com/reference/kotlin/androidx/core/os/package-summary#bundleOf%28kotlin.Pair%29
The import line should be something like: import androidx.core.os.bundleOf
Related
I am trying to make a RecyclerView in Android Studio and I am struggling to inherit from RecyclerView.Adapter<>()
This is the fragment of code that contains the problem:
package Adapters
import androidx.appcompat.app.AppCompatActivity
import androidx.recyclerview.R
import android.os.Bundle
import models.Post
class PostAdapter(private val postList: List<Post>, private val content: String) : RecyclerView.Adapter<PostAdapter.PostViewHolder>() {
Android Studio sets "RecyclerView" red and I can't get rid of it. I tried solutions from other posts on stackoverflow, tried to follow tutorials on the internet, but there isn't anything about androidx and I can't use older version (android.support.v7.widget.RecyclerView), because Android Studio won't let me.
I imported RecyclerView in mains build.gradle:
implementation "androidx.recyclerview:recyclerview:1.1.0"
And added google() in the highest-instance build.gradle
I hope I explained the problem properly and you can help me.
I think you are missing import of recycler view
import androidx.recyclerview.widget.RecyclerView
Also If you've just migrated to Android X Android studio might be buggy so you want to do File -> Invalidate Caches/Restart
SOLVED!
Did you remember to specify an id for the recyclerview after adding it to your main activity? If yes, then check to make sure that the id you gave is exactly the same as the red text that's causing an unresolved error. Eg
If in main_activity.xml you have
`<androidx.recyclerview.widget.RecyclerView
android:id="#+id/recyclerView"
android:layout_width="409dp"
android:layout_height="729dp"
tools:layout_editor_absoluteX="1dp"
tools:layout_editor_absoluteY="1dp" />`
Then in MainActivity.kt you should have
`recyclerView.layoutManager = StaggeredGridLayoutManager(1, StaggeredGridLayoutManager.VERTICAL)`
The word "recyclerView" should be exactly the same in the 2 files where it is used
In my case, I was using the wrong library version.
My library version was way too greater than the released version.
implementation 'androidx.recyclerview:recyclerview:2.9.0'
implementation 'androidx.recyclerview:recyclerview:1.2.1'
I am trying to reference the Fitness.SENSOR_API as documented (https://developers.google.com/android/reference/com/google/android/gms/fitness/Fitness.html#SENSORS_API).
In java I import
import com.google.android.gms.fitness.Fitness;
and reference it like
Fitness.SENSORS_API
but this doesn't seem to work in nativescript (referencing it as com.google.android.gms.fitness.Fitness.SENSORS_API).
I've logged the value :
console.log('fitness native module:',
com.google.android.gms.fitness.Fitness); //Fitness is undefined
The same is true for other classes in the com.google.android.gms.fitness package for example com.google.android.gms.fitness.FitnessOptions as referenced here: https://developers.google.com/android/reference/com/google/android/gms/fitness/FitnessOptions.Builder
Overall, Here is what I'm trying to do:
googleApiClient = new com.google.android.gms.common.api.GoogleApiClient.Builder(activity)
.addApi(com.google.android.gms.fitness.Fitness.SENSORS_API)
.addApi(com.google.android.gms.fitness.Fitness.HISTORY_API)
.addApi(com.google.android.gms.fitness.Fitness.RECORDING_API)
.addScope('https://www.googleapis.com/auth/fitness.activity.read')
.addScope('https://www.googleapis.com/auth/fitness.activity.write')
.addScope('https://www.googleapis.com/auth/fitness.location.read')
.build();
I do have
dependencies {
implementation 'com.google.android.gms:play-services-fitness:16.0.1'
implementation 'com.google.android.gms:play-services-auth:16.0.1'
}
in my App_Resources/Android/app.gradle file.
Am I missing something? Do I need to extend or implement some class? Why is Fitness undefined?
My overall goal is to follow these docs (https://developers.google.com/fit/android/get-started) and connect to google fitness API
Try a clean build to make sure the dependencies are installed properly, accessing the package might return undefined only in such cases.
tns platform clean android
I am encountering following error while building an apk:
error: package android.arch.core.util does not exist
My java code has a line:
import android.arch.core.util.Function;
I know this exists and its doc is here.
But how can I import it?
There was a versioning problem and my problem solved with this link:
https://issuetracker.google.com/issues/66894924#comment12
I used beta version of libs and it solved the error about android.arch.core.util.Function;
I'm not sure what you are using it for but here is a sample that compiles and runs. Add the import to the class that needs it and add the code somewhere in that same class. Android Studio would not let me import it until I had code that actually used it. It may be a bug or intentional.
Import:
import android.arch.core.util.Function;
Code:
Function function = new Function<Boolean, String>() {
#Override
public String apply(Boolean input) {
return null;
}
};
Please make sure you have added the corresponding dependency in gradle
Example
implementation "android.arch.lifecycle:extensions:1.1"
Final answer
Add the below code in app/build.gradle file under "dependencies" block
// Room components
implementation "android.arch.persistence.room:runtime:1.1.0”
annotationProcessor "android.arch.persistence.room:compiler:1.1.0"
androidTestImplementation "android.arch.persistence.room:testing:1.1.0"
// Lifecycle components
implementation "android.arch.lifecycle:extensions:1.1.0"
annotationProcessor "android.arch.lifecycle:compiler:1.1.0"
I'm trying to observe observable on main thread by using:
// Kotlin Code
Observable
.observeOn(AndroidSchedulers.mainThread())
but I'm getting following error:
Type Mismatch:
Required: rx.Scheduler!
Found: io.reactivex.Scheduler!
The Observable I'm subscribing to is from a Library that is written in Java and therefore uses RxJava.
Am i being stupid and missing something? I'm puzzeled :$
Thanks in advance :)
Required: rx.Scheduler!
Required means the signature is Observable.observeOn(rx.Scheduler)
Found: io.reactivex.Scheduler!
Found means the signature is io.reactivex.Scheduler AndroidSchedulers.mainThread()
This means that the Observable is a RxJava 1 observable, while the RxAndroid version used is built for RxJava 2. Since you mentioned that the observable is provided by a library it means that library is built using RxJava 1.
You have 3 options to fix this:
Figure out if the library in question has an RxJava 2 version, or contribute those updates to the project yourself.
Use akarnokd/RxJava2Interop to convert the old Observable to RxJava 2. (RxJavaInterop.toV2Observable(Observable);)
Switch the other dependencies back to RxJava 1.
1.add :
//RX JAVA
implementation "io.reactivex.rxjava3:rxjava:3.0.0-RC6"
implementation "io.reactivex.rxjava2:rxandroid:2.0.2"
2.Write this code :
val taskObservable: Observable<Task> = Observable.fromIterable(DataSource.createTaskList())
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
}
3.add these imports :
import io.reactivex.Observable
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.disposables.Disposable
import io.reactivex.functions.Function
import io.reactivex.schedulers.Schedulers
NOTE :
if you are using KOTLIN, So it is better to use RX Kotlin!
just add two lines in your build.gradle :
//rxkotlin
implementation "io.reactivex.rxjava2:rxkotlin:2.4.0"
implementation "io.reactivex.rxjava2:rxandroid:2.0.2"
please include this in your gradle import
rxandroid_version="2.0.1"
implementation "io.reactivex.rxjava2:rxandroid:$rxandroid_version"
add this to your project
import io.reactivex.android.schedulers.AndroidSchedulers
use
.subscribeOn(io.reactivex.rxjava3.schedulers.Schedulers.io())
Try to use these dependencies it works for me :
implementation 'io.reactivex.rxjava2:rxandroid:2.1.1'
implementation 'io.reactivex.rxjava2:rxjava:2.x.x'
Hi i want to use ArcAnimator and ArcLayout in one android project .
for that i using this dependencys
compile 'com.ogaclejapan.arclayout:library:1.0.1#aar'
compile 'com.github.asyl.animation:arcanimator:1.0.0'
but i give this error message
cannot resolve symbol'SupportAnimator'
cannot resolve symbol'ViewAnimationUtils'
in import line
import io.codetail.animation.SupportAnimator;
import io.codetail.animation.ViewAnimationUtils;
and its strange because i do not give this error in this lines
import io.codetail.animation.arcanimator.ArcAnimator;
import io.codetail.animation.arcanimator.Side;
which is in same library.
can anyone help me about that?
You have to use other dependency to use Support Animator say https://github.com/kedzie/Support_v4_NineOldAndroids. Support Animator is not there in the package of the library that you have used. It’s not showing inside the package you have used, you can check at https://github.com/asyl/ArcAnimator/tree/master/animator/src/main/java/io/codetail/animation/arcanimator.
Also you can take help of some samples given here at https://github.com/ozodrukh/CircularReveal/releases.