incompatible types: MainActivity cannot be converted to LifecycleOwner

Marwa Eltayeb

MainActivity cannot be converted to LifecycleOwner I used this as LiveCycle Owner, but it is rejected and I got an error as you see in the picture. I work on Api 25 and I this the problem may be related to this version This is info about my sdk

compileSdkVersion 25
buildToolsVersion '25.0.2'

This is my code:

private void retrieveTasks() {
    Log.d(TAG, "Actively retrieving the tasks from the DataBase");
    // Extract all this logic outside the Executor and remove the Executor
    // Fix compile issue by wrapping the return type with LiveData
    LiveData<List<TaskEntry>> tasks = mDb.taskDao().loadAllTasks();
    // Observe tasks and move the logic from runOnUiThread to onChanged
    tasks.observe(this, new Observer<List<TaskEntry>>() {
        @Override
        public void onChanged(@Nullable List<TaskEntry> taskEntries) {
            Log.d(TAG, "Receiving database update from LiveData");
            mAdapter.setTasks(taskEntries);
        }
    });
}

I put LiveData dependencies in my Gradle

compile "android.arch.lifecycle:extensions:1.0.0"
annotationProcessor "android.arch.lifecycle:compiler:1.0.0"

If anyone knows the reason for the problem, let me know please

AmrDeveloper

Good question

Fragments and Activities in Support Library 26.1.0 and later already implement the LifecycleOwner interface by default

but in version 25 you need to implement LifecycleOwner interface for example

public class MyActivity extends Activity implements LifecycleOwner {
    private LifecycleRegistry mLifecycleRegistry;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        mLifecycleRegistry = new LifecycleRegistry(this);
        mLifecycleRegistry.markState(Lifecycle.State.CREATED);
    }

    @Override
    public void onStart() {
        super.onStart();
        mLifecycleRegistry.markState(Lifecycle.State.STARTED);
    }

    @NonNull
    @Override
    public Lifecycle getLifecycle() {
        return mLifecycleRegistry;
    }
}

Source : Handling lifecycles with lifecycle-aware components

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Android Studio: error: incompatible types: MainActivity cannot be converted to Application

From Dev

incompatible types: Node cannot be converted to Tab

From Java

incompatible types: int cannot be converted to T

From Java

Java incompatible types: int cannot be converted to int[]

From Dev

incompatible types: HomeFragment cannot be converted to Fragment in Android

From Java

Java : incompatible types; int cannot be converted to string

From Dev

Incompatible types: Fragment cannot be converted to NavigationDrawerFragment

From Dev

Error: incompatible types: double cannot be converted to JTextField

From Dev

Error: incompatible types: Object cannot be converted to char

From Dev

incompatible types: void cannot be converted to int

From Dev

incompatible types: BigInteger cannot be converted to int

From Dev

Incompatible types: Object cannot be converted to ParseObject

From Dev

Java incompatible types: int cannot be converted to int[]

From Dev

incompatible types: char[] cannot be converted to CharSequence

From Dev

error: incompatible types: MainFragment cannot be converted to Activity

From Dev

incompatible types: FragmentDark cannot be converted to Fragment in Android

From Dev

Error: incompatible types: Object cannot be converted to char

From Dev

incompatible types: BigInteger cannot be converted to int

From Dev

incompatible types: Object cannot be converted to CoreLabel

From Dev

Java JComboBox Incompatible Types: Cannot be converted to string

From Dev

error: incompatible types: Object cannot be converted to MyClass

From Dev

incompatible types: String[] cannot be converted to String

From Dev

error: incompatible types: int[][] cannot be converted to int

From Dev

Error:(124, 62) error: incompatible types: Class cannot be converted to Context

From Dev

Why am I getting, "incompatible types: Object cannot be converted to String" with this?

From Java

error: incompatible types: <anonymous Callback<List<UserDataResponse>>> cannot be converted to OnNoteListener

From Dev

JAVA incompatible types: Object cannot be converted to my type

From Dev

Java: toString error "error: incompatible types: int cannot be converted to String"

From Dev

app setBackground() error: incompatible types: int cannot be converted to Drawable

Related Related

  1. 1

    Android Studio: error: incompatible types: MainActivity cannot be converted to Application

  2. 2

    incompatible types: Node cannot be converted to Tab

  3. 3

    incompatible types: int cannot be converted to T

  4. 4

    Java incompatible types: int cannot be converted to int[]

  5. 5

    incompatible types: HomeFragment cannot be converted to Fragment in Android

  6. 6

    Java : incompatible types; int cannot be converted to string

  7. 7

    Incompatible types: Fragment cannot be converted to NavigationDrawerFragment

  8. 8

    Error: incompatible types: double cannot be converted to JTextField

  9. 9

    Error: incompatible types: Object cannot be converted to char

  10. 10

    incompatible types: void cannot be converted to int

  11. 11

    incompatible types: BigInteger cannot be converted to int

  12. 12

    Incompatible types: Object cannot be converted to ParseObject

  13. 13

    Java incompatible types: int cannot be converted to int[]

  14. 14

    incompatible types: char[] cannot be converted to CharSequence

  15. 15

    error: incompatible types: MainFragment cannot be converted to Activity

  16. 16

    incompatible types: FragmentDark cannot be converted to Fragment in Android

  17. 17

    Error: incompatible types: Object cannot be converted to char

  18. 18

    incompatible types: BigInteger cannot be converted to int

  19. 19

    incompatible types: Object cannot be converted to CoreLabel

  20. 20

    Java JComboBox Incompatible Types: Cannot be converted to string

  21. 21

    error: incompatible types: Object cannot be converted to MyClass

  22. 22

    incompatible types: String[] cannot be converted to String

  23. 23

    error: incompatible types: int[][] cannot be converted to int

  24. 24

    Error:(124, 62) error: incompatible types: Class cannot be converted to Context

  25. 25

    Why am I getting, "incompatible types: Object cannot be converted to String" with this?

  26. 26

    error: incompatible types: <anonymous Callback<List<UserDataResponse>>> cannot be converted to OnNoteListener

  27. 27

    JAVA incompatible types: Object cannot be converted to my type

  28. 28

    Java: toString error "error: incompatible types: int cannot be converted to String"

  29. 29

    app setBackground() error: incompatible types: int cannot be converted to Drawable

HotTag

Archive