Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Activity view's presenter is not attached on first creation #47

Open
blackvvine opened this issue Aug 31, 2018 · 0 comments
Open

Activity view's presenter is not attached on first creation #47

blackvvine opened this issue Aug 31, 2018 · 0 comments

Comments

@blackvvine
Copy link

blackvvine commented Aug 31, 2018

Hi,

I ran into this weird problem where the Activity view's presenter is created but not attached the first time the activity is created. After that, if for example I press the home button and return to the activity everything works fine and the view is attached to the presenter with onStart().

Here is my code:

@ActivityView(layout = R.layout.activity_wallet_new, presenter = TestPresenter::class)
class TestActivity : AppCompatActivity(), TestView {

    @Presenter
    @JvmField
    var presenter: TestPresenter? = null

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        Horizon.zero(this).statusBarColor(R.color.statusBarColor).dawn()
    }

    override fun onStart() {
        super.onStart()
        Timber.d("onStart: presenter=%s", presenter)
    }
}

presenter:

class TestPresenter: AbstractPresenter<TestView>() {

    init {
        Timber.d("init: test presenter created")
    }

    override fun onViewAttached(view: TestView?) {
        super.onViewAttached(view)
        Timber.d("onViewAttached: called")
    }

    override fun onViewDetached() {
        super.onViewDetached()
        Timber.d("onViewDetached: called.")
    }
}

view interface:

interface TestView {
}

build.gradle:

android {
    compileSdkVersion 27
    defaultConfig {
        applicationId "com.exmample.foo"
        minSdkVersion 19
        targetSdkVersion 27
        versionCode 6
        versionName "1.0.6"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        vectorDrawables.useSupportLibrary = true
    }
    buildTypes {
        release {
            minifyEnabled true
            shrinkResources true
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    buildToolsVersion '28.0.1'
}

easymvp version:

        classpath 'com.sixthsolution.easymvp:easymvp-plugin:1.2.0-beta10'

Note that the presenter constructor is called even on the first creation, it is just that it isn't attached (i.e. onViewAttached is not called and presenter is null in onStart() of the activity)

I tried rewriting everything in Java just to make sure it's not some freaky kapt problem. I also tried using an injected presenter and everything was the same.

Any ideas?

UPDATE:

here's the log output. I just realized when it's on Java, neither attach or detach is called the first time. On Kotlin, it even calls onViewDetached the first time but onViewAttached is only called from the second time on, here's the log output for Kotlin:

D/TestActivity: onStart: presenter=null
D/TestPresenter: init: test presenter created

[HIT HOME BUTTON AND RETURN TO ACTIVITY]

D/TestPresenter: onViewDetached: called.
D/TestPresenter: onViewAttached: called
D/TestActivity: onStart: presenter=com.example.foo.domain.TestPresenter@9c8b130

Now I'm really confused.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant