SupportMapFragment / getSupportFragmentManager with CoronaActivity

Since CoronaActivity is based on Activity I’m unable to add a SupportMapFragment to the view.  I have been successful by creating a new FragmentActivity, adding the map there and starting that new activity.   This feels a bit clunky.  My android skills are pretty light when it comes to fragments so am I missing something that would allow adding the map directly to the CoronaActivity?

I also see that the Corona-provided map view is actually a web view that points to google maps.  I’m guessing that since this was the implementation choice by Corona, my current solution is the only viable option.

Is anyone else using native google maps?

Corona uses a WebView for maps because Google’s native map feature is not available on all Android devices.  Particularly on Amazon Kindles, Fire Phones, and Barnes&Noble Nook tablets.  So, our WebView implementation makes it available on all Android devices.

Android fragments is a feature that is only available on Android 3.x and newer devices.  Since Corona still needs to support Android 2.3 devices, which is still a significant portion of the market place, that is why we chose to implement Corona within an activity.

But that said, what you can do is using Google’s Android “Support Library” (see link below), which can encapsulate fragments.  Corona leverages this library for the newest Facebook SDK which uses fragments for some features.  Google’s Support Library can be downloaded via the Android SDK Manager; the same desktop app you use to download Android’s different API levels.

   http://developer.android.com/tools/support-library/features.html

Just remember that by using Google’s native maps feature, you can only reliably deploy your app to the Google Play store.  You’ll likely get rejected by the Amazon app store if you try to use it… unless of course you use a fallback mechanism to use a different maps implementation.  (Amazon has their own native maps feature that they would probably prefer you to use.)

Joshua:

I am using the support library so I can support 2.3.x and later devices.  This is an application that won’t be available on Amazon for now since yes, they have completely different mapping services.

That being said, since CoronaActivity isn’t derived from FragmentActivity I don’t have the getSupportFragmentManager method available unless I start a new activity.  Looking at the manifest, this appears to be exactly what Facebook is doing since I see a “com.ansca.corona.facebook.FacebookFragmentActivity” defined. 

I have done the same thing, registered a new activity that is derived from FragmentActivity and (native) google maps work as I expect.  However since I’m in a new activity, I get the (not surprising) suspend callbacks in my lua code which isn’t ideal, which is why I referred to this solution as clunky.  

Well, if you display a map fullscreen via a fragment activity, ideally you would want the Corona runtime to be suspended, right?

Your only other option is to use CoronaCards, where Corona is provided as an Android derived View.  With this, you can add our CoronaView to your own Activity and control the lifecycle of the Corona runtime yourself.  However, this adds much more complexity on your end because several features are not available to Corona from within a view… particularly since we don’t have the features provided by the activity.

For the sake of simplicity, I think what you’re doing now would be the most productive means of implementing this.  There really isn’t any one good solution to this problem on Android.  Particularly if you still want to target Android 2.3.

Joshua:

Thanks for the additional info. I believe I can get the functionality I’m looking for with the fragment activity that I’ve implemented.

Corona uses a WebView for maps because Google’s native map feature is not available on all Android devices.  Particularly on Amazon Kindles, Fire Phones, and Barnes&Noble Nook tablets.  So, our WebView implementation makes it available on all Android devices.

Android fragments is a feature that is only available on Android 3.x and newer devices.  Since Corona still needs to support Android 2.3 devices, which is still a significant portion of the market place, that is why we chose to implement Corona within an activity.

But that said, what you can do is using Google’s Android “Support Library” (see link below), which can encapsulate fragments.  Corona leverages this library for the newest Facebook SDK which uses fragments for some features.  Google’s Support Library can be downloaded via the Android SDK Manager; the same desktop app you use to download Android’s different API levels.

   http://developer.android.com/tools/support-library/features.html

Just remember that by using Google’s native maps feature, you can only reliably deploy your app to the Google Play store.  You’ll likely get rejected by the Amazon app store if you try to use it… unless of course you use a fallback mechanism to use a different maps implementation.  (Amazon has their own native maps feature that they would probably prefer you to use.)

Joshua:

I am using the support library so I can support 2.3.x and later devices.  This is an application that won’t be available on Amazon for now since yes, they have completely different mapping services.

That being said, since CoronaActivity isn’t derived from FragmentActivity I don’t have the getSupportFragmentManager method available unless I start a new activity.  Looking at the manifest, this appears to be exactly what Facebook is doing since I see a “com.ansca.corona.facebook.FacebookFragmentActivity” defined. 

I have done the same thing, registered a new activity that is derived from FragmentActivity and (native) google maps work as I expect.  However since I’m in a new activity, I get the (not surprising) suspend callbacks in my lua code which isn’t ideal, which is why I referred to this solution as clunky.  

Well, if you display a map fullscreen via a fragment activity, ideally you would want the Corona runtime to be suspended, right?

Your only other option is to use CoronaCards, where Corona is provided as an Android derived View.  With this, you can add our CoronaView to your own Activity and control the lifecycle of the Corona runtime yourself.  However, this adds much more complexity on your end because several features are not available to Corona from within a view… particularly since we don’t have the features provided by the activity.

For the sake of simplicity, I think what you’re doing now would be the most productive means of implementing this.  There really isn’t any one good solution to this problem on Android.  Particularly if you still want to target Android 2.3.

Joshua:

Thanks for the additional info. I believe I can get the functionality I’m looking for with the fragment activity that I’ve implemented.