androidx lifecycle observer incompability
See original GitHub issueHey, after plenty of unsuccessful attempts on using the official youtube api together with androidx, I was recommended to use this library- which seems a whole lot more comprehensive and supported. Unfortunately, I’m still stuck with the detail that lifecycle requires observer to be of androidx type.
build.gradle:
apply plugin: 'com.android.application'
apply plugin: 'com.google.android.gms.oss-licenses-plugin'
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.moomoo.testapp"
minSdkVersion 21
targetSdkVersion 28
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
def lifecycle_version = "1.1.1"
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'com.google.android.material:material:1.0.0' // Material design
implementation 'com.github.PhilJay:MPAndroidChart:v3.0.3' // Graphs
implementation 'com.pierfrancescosoffritti.androidyoutubeplayer:core:8.0.1' // Youtube
implementation "androidx.lifecycle:lifecycle-viewmodel:$lifecycle_version"
}
public class SingleTestFragment extends Fragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_single_test, container, false);
YouTubePlayerView youtubePlayerView = rootView.findViewById(R.id.youtube_player_view);
getLifecycle().addObserver(youtubePlayerView); <---- issue with androidx and library
youtubePlayerView.initialize(new YouTubePlayerInitListener() {
@Override
public void onInitSuccess(@NonNull final YouTubePlayer initializedYouTubePlayer) {
initializedYouTubePlayer.addListener(new AbstractYouTubePlayerListener() {
@Override
public void onReady() {
String videoId = "6JYIGclVQdw";
initializedYouTubePlayer.loadVideo(videoId, 0);
}
});
}
}, true);
return rootView;
}
}
I wouldnt mind doing the mentioned workaround, of manually releasing the player, if necessary - but I was also unable to figure that one out. Any suggestions?
Issue Analytics
- State:
- Created 5 years ago
- Comments:21 (10 by maintainers)
Top Results From Across the Web
Lifecycle - Android Developers
Lifecycle-aware components perform actions in response to a change in the lifecycle status of another component, such as activities and fragments.
Read more >incompatible types androidx observer method - Stack Overflow
I'm trying to figure out MVVM.I figured out how to observe LiveData using ViewModel. Now I encountered a problem. private void ...
Read more >What are Lifecycle-Aware Components in Android? - Medium
Every LifecycleOwner has Lifecycle, based on EVENT or STATE of this Lifecycle of LifecycleOwner, LifecycleObserver performs the action. Hands-On Project . We ......
Read more >NI: TYPE_MISMATCH: "inferred type is Unit but Observer<T ...
Fragment import androidx.lifecycle.LifecycleOwner import androidx.lifecycle.LiveData import androidx.lifecycle.Observer import androidx.lifecycle.observe ...
Read more >[Solved]-Android (Kotlin): Type mismatch in Observer-kotlin
this it should compile. viewModel.getSchedule().observe(this, object :androidx.lifecycle.Observer<in String> { override fun onChanged(t: String?) { TODO(" ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
While searching for solution to a different problem, I got this one working 👍 So now I’m using it (and you got a star, and soon license mention of course).
The solution was to add the two below attributes to my gradle.properties file
I’ve just updated the library to depend on androidx, new updated coming soon.