yandex/mapkit-android-demo

Yandex Map Set Api Key Error

CihatBostanci opened this issue · 1 comments

Hello ;
I have already integrated Yandex Map to my project however when the application on background and come again to app, it gives crash as in the following;
Could you help me please ?

   override fun onCreate(savedInstanceState: Bundle?) {
       super.onCreate(savedInstanceState)
       MapKitFactory.setApiKey(BuildConfig.MAPKIT_API_KEY)
       MapKitFactory.initialize(this@MainActivity)
  }
Fatal Exception: java.lang.AssertionError: setApiKey() should be called before initialize()!
   at com.yandex.mapkit.MapKitFactory.setApiKey(:15)
   at com.odeontechnology.baseproject.MainActivity.onCreate(MainActivity.java:34)
   at android.app.Activity.performCreate(Activity.java:8975)
   at android.app.Activity.performCreate(Activity.java:8944)
   at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1456)
   at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:4146)
   at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:4322)
   at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:103)
   at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:139)
   at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:96)
   at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2685)
   at android.os.Handler.dispatchMessage(Handler.java:106)
   at android.os.Looper.loopOnce(Looper.java:230)
   at android.os.Looper.loop(Looper.java:319)
   at android.app.ActivityThread.main(ActivityThread.java:8919)
   at java.lang.reflect.Method.invoke(Method.java)
   at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:578)
   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1103)

The message says that you need to set the API key with setApiKey before initializing using initialize.

If the issue is not resolved, please send us a minimal example of your situation. You can upload it as a project on GitHub or upload it to Yandex Disk and provide a link.