[mono-android] Generic Activity
Jonathan Pryor
jonp at xamarin.com
Thu Dec 22 10:13:55 EST 2011
On Dec 21, 2011, at 10:46 PM, John Moore wrote:
> [Activity (Label =
> "@string/lookupLabel",Theme="@android:style/Theme.Dialog")]
> public class LookupActivity<TEntity> : ListActivity where TEntity : IEntity
> {}
> so then my main activity invokes this activity like so...
> StartActivity(typeof(LookupActivity<AmpachePlaylist>));
This won't work, because an Android Callable Wrapper will be generated for LookupActivity<T> (as LookupActivity_1), but not for LookupActivity<AmpachePlaylist>. Thus, when Android attempts to create a LookupActivity_1, we'll attempt to run the managed side constructor, which will fail as 'T' is unknown (and not knowable).
I'm not even sure if it's possible to make it work, either.
Finally, it doesn't make sense to me, as the purpose of an Activity (generally) is to instantiate a single user-visible screen. By making it generic, you're providing a _set_ of such activities, but the UI will still display only one icon, so how is your app supposed to know which one of the set was desired?
- Jon
More information about the Monodroid
mailing list