1

Basically I have a project written in Kotlin and Dagger2. I am trying to implement one base feature. Most examples do not specify <application android:name=".MyApplication" .... >. I need to use an Application object to call android Injector from MyApplication.onCreate(), but from my debugger I never see MyApplication object being called. So, my activity cannot inject an object.

I tried using tools:replace to use another Application object, but still no luck (Separate manifest for instant app).

Please help.

andude
  • 500
  • 1
  • 5
  • 11
  • 1
    Can you file a bug with a sample app (https://stackoverflow.com/help/mcve) that demonstrates your issue and then link to it back in here? It would be helpful for all, thanks! https://issuetracker.google.com/issues/new?component=316045&template=1018787 – Julia K Sep 20 '17 at 18:09

2 Answers2

1

The Android Studio debugger may miss some things that happen early in the application life cycle---we're working on fixing that.

I tried creating a MyApplication which just logs something in onCreate(), and the log statement shows up.

dchai
  • 231
  • 2
  • 4
  • Yes, the Application.onCreate() is called but somehow we are using latest Android Architecture components issue. When it tries to registerActivityLifecycleCallbacks(), activity.getApplication() returns null Application object. I tried it with and without specific Application class. – andude Sep 20 '17 at 16:55
0

With the help of Google dev in root causing the (Android Architecture Components related) issue, the issue is now resolved. See issue 65989760 for more details. - Application object cannot be obtained by an activity's constructor. It has to be done on activity.onCreate(). - So, I moved my logic declared as a Kotlin var to onCreate() and it fixed the issue.

override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)

    viewModel.orderHistoryLiveData.observe(this, Observer {
        viewModel.listVisible.set(it?.isNotEmpty() ?: false)
    })
}
andude
  • 500
  • 1
  • 5
  • 11